Professional Documents
Culture Documents
In [1]:
import numpy as np
import pandas as pd
In [31]:
#creating data frame using list of tuples
In [32]:
emp_data=[(111,'Akash',30000),(222,'Mishra',40000),(333,'Gaurav',50000)]
In [70]:
df=pd.DataFrame(emp_data,index=['Emp#01','Emp#02','Emp#03'],columns=['eno','ename','
In [71]:
df
In [41]:
df[['eno','ename']]
In [43]:
df.loc['Employee#01']
ename Akash
esal 30000
In [52]:
df.iloc[0:2,0:2]
In [53]:
#creating data frames using dictionary
In [54]:
weather_data={
'day':['01/01/2020','01/02/2020','01/03/2020','01/04/2020','01/05/2020','01/06/2
'temperature':[32,35,28,24,32,31],
'windspeed': [6,7,2,7,4,2],
'event':['rain','sunny','snow','snow','rain','sunny']
localhost:8888/nbconvert/html/pandas_practical/pandas_tutorial.ipynb?download=false 1/3
7/30/2021 pandas_tutorial
In [55]:
df1=pd.DataFrame(weather_data)
In [56]:
df1
0 01/01/2020 32 6 rain
1 01/02/2020 35 7 sunny
2 01/03/2020 28 2 snow
3 01/04/2020 24 7 snow
4 01/05/2020 32 4 rain
5 01/06/2020 31 2 sunny
In [61]:
df1['temperature'].value_counts()
Out[61]: 32 2
35 1
28 1
24 1
31 1
In [62]:
df1['temperature'].unique()
In [63]:
df1['temperature'].max()
Out[63]: 35
In [64]:
#conditionally select data
In [65]:
df1[df1.temperature>=32]
0 01/01/2020 32 6 rain
1 01/02/2020 35 7 sunny
4 01/05/2020 32 4 rain
In [69]:
df1[['day','temperature']] [df1.temperature>=32]
localhost:8888/nbconvert/html/pandas_practical/pandas_tutorial.ipynb?download=false 2/3
7/30/2021 pandas_tutorial
day temperature
0 01/01/2020 32
1 01/02/2020 35
4 01/05/2020 32
In [ ]:
localhost:8888/nbconvert/html/pandas_practical/pandas_tutorial.ipynb?download=false 3/3