You are on page 1of 3

7/30/2021 pandas_tutorial

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

Out[71]: eno ename esal

Emp#01 111 Akash 30000

Emp#02 222 Mishra 40000

Emp#03 333 Gaurav 50000

In [41]:
df[['eno','ename']]

Out[41]: eno ename

Employee#01 111 Akash

Employee#02 222 Mishra

Employee#03 333 Gaurav

In [43]:
df.loc['Employee#01']

Out[43]: eno 111

ename Akash

esal 30000

Name: Employee#01, dtype: object

In [52]:
df.iloc[0:2,0:2]

Out[52]: eno ename

Employee#01 111 Akash

Employee#02 222 Mishra

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

Out[56]: day temperature windspeed event

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

Name: temperature, dtype: int64

In [62]:
df1['temperature'].unique()

Out[62]: array([32, 35, 28, 24, 31], dtype=int64)

In [63]:
df1['temperature'].max()

Out[63]: 35

In [64]:
#conditionally select data

In [65]:
df1[df1.temperature>=32]

Out[65]: day temperature windspeed event

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]

Out[69]: day temperature

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

You might also like