Pandas Session 2 Code

  Pandas Session 2 Code For Video Click Fahad Hussain CS


Hi, Welcome to Fahad Hussain CS blog, do not forget to subscribe and follow the blog and YouTube channel  Fahad Hussain CS

Code:

import pandas as pd


data = {'State':['Khi','Lhr','Mul','Isl','Haz','Raw'],

'Year':[2000,2001,2002,2003,2004,2005],

'Pop':[1.5,1.6,2.5,4.2,3.5,1.9]}


frame1 = pd.DataFrame(data)

print(frame1)

print(type(frame1))


frame2 = pd.DataFrame(data, columns=['State','Year','Pop','Debt'],

                      index =['one','two','three','four','five','six'])

print(frame2)


frame2['Debt'] = 15

print(frame2)


import numpy as np

frame2['Debt'] = np.arange(6)

print(frame2)


val = pd.Series([55,66,8,9,52,45],index =['one','two','three','four','five','six'])

frame2['Debt'] = val

print(frame2)


frame2['Earn'] = frame2.Year

print(frame2)


del frame2['Earn']

print(frame2)


frame2.iloc[3,1] = 2010

print(frame2)


frame2.rename(columns={'State':'States','Year':'Years','Pop':'Pops','Debt':'Debts'},inplace=True)

print(frame2)


No comments:

Post a Comment

Fell free to write your query in comment. Your Comments will be fully encouraged.