/ Python And R Data science skills: 55 Opreators ond mis functions Part01
Showing posts with label 55 Opreators ond mis functions Part01. Show all posts
Showing posts with label 55 Opreators ond mis functions Part01. Show all posts

Saturday, 10 February 2018

55 Opreators ond mis functions Part01

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 55 Opreators ond mis functions
In [25]:
import pandas as pd
df = pd.DataFrame({'col1':[1,2,3,4],'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})
In [5]:
df.head(n=1)
Out[5]:
col1 col2 col3
0 1 444 abc
In [3]:
df
Out[3]:
col1 col2 col3
0 1 444 abc
1 2 555 def
2 3 666 ghi
3 4 444 xyz
In [7]:
df['col2'].unique()
Out[7]:
array([444, 555, 666], dtype=int64)
In [8]:
df['col2'].nunique()
Out[8]:
3
In [9]:
newdf = df[(df['col1']>2) & (df['col2']==444)]
In [12]:
df[(df["col2"]>450) & (df["col2"]<600)]
Out[12]:
col1 col2 col3
1 2 555 def
In [13]:
def doub(x):
    return x*2
In [15]:
doub(9)
Out[15]:
18
In [16]:
df
Out[16]:
col1 col2 col3
0 1 444 abc
1 2 555 def
2 3 666 ghi
3 4 444 xyz
In [17]:
df['col2'].apply(doub)
Out[17]:
0     888
1    1110
2    1332
3     888
Name: col2, dtype: int64
In [18]:
df['col3'].apply(len)
Out[18]:
0    3
1    3
2    3
3    3
Name: col3, dtype: int64
In [19]:
df['col2'].sum()
Out[19]:
2109
In [26]:
#del df['col1']
df
Out[26]:
col1 col2 col3
0 1 444 abc
1 2 555 def
2 3 666 ghi
3 4 444 xyz
In [29]:
df.index
df.columns
Out[29]:
Index(['col1', 'col2', 'col3'], dtype='object')
In [34]:
df.sort_values('col3',ascending=False)
Out[34]:
col1 col2 col3
3 4 444 xyz
2 3 666 ghi
1 2 555 def
0 1 444 abc
In [35]:
df.isnull()
Out[35]:
col1 col2 col3
0 False False False
1 False False False
2 False False False
3 False False False