/ Python And R Data science skills: 41 Python Pandas Series part 01
Showing posts with label 41 Python Pandas Series part 01. Show all posts
Showing posts with label 41 Python Pandas Series part 01. Show all posts

Monday, 5 February 2018

41 Python Pandas Series part 01

41 Python Pandas - Series

Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index. https://www.tutorialspoint.com/python_pandas/python_pandas_series.htm

In [1]:
import numpy as np
import pandas as pd
In [2]:
ser1=pd.Series(data=["venkat","balaji","vijay"],index=["dm","ds","rpa"])
In [3]:
ser1
Out[3]:
dm     venkat
ds     balaji
rpa     vijay
dtype: object
In [4]:
ser2=pd.Series(["venkat","balaji","Praven"],["dm","ds","ajs"])
In [5]:
ser2
Out[5]:
dm     venkat
ds     balaji
ajs    Praven
dtype: object
In [6]:
ser1+ser2
Out[6]:
ajs             NaN
dm     venkatvenkat
ds     balajibalaji
rpa             NaN
dtype: object
In [7]:
ser3=pd.Series(["a","c","d"])
In [8]:
ser3
Out[8]:
0    a
1    c
2    d
dtype: object

In [9]:
ser1["dm"]
Out[9]:
'venkat'
In [28]:
la = ['k','M1','z']
li = [10,20,30]
a1 = np.array(li)
di = {'a':10,'b':20,'c':30}
In [12]:
la
Out[12]:
['a', 'b', 'c']
In [13]:
li
Out[13]:
[10, 20, 30]
In [14]:
a1
Out[14]:
array([10, 20, 30])
In [15]:
di
Out[15]:
{'a': 10, 'b': 20, 'c': 30}
In [16]:
la = ['a','b','c']
li = [10,20,30]
a1 = np.array(li)
di = {'a':10,'b':20,'c':30}
In [17]:
se1=pd.Series(di)
In [18]:
se1
Out[18]:
a    10
b    20
c    30
dtype: int64
In [19]:
se2=pd.Series(data=li,index=la)
In [20]:
se2
Out[20]:
a    10
b    20
c    30
dtype: int64
In [22]:
se2=pd.Series(li,la)
In [23]:
se2
Out[23]:
a    10
b    20
c    30
dtype: int64
In [25]:
se2["c"]
Out[25]:
30
In [31]:
se3=pd.Series(la,di)
In [32]:
se3
Out[32]:
a     k
b    M1
c     z
dtype: object
In [35]:
se4=pd.Series(a1,la)
In [36]:
se4
Out[36]:
k     10
M1    20
z     30
dtype: int32