IP REVISION
#ASSIGNMENT SOLUTIONS
#1
import pandas as pd
'''
a=[{'name':'virat','matches Played':180,'avg score':4500},
{'name':'rohit','matches Played':190,'avg score':4700},
{'name':'Dhoni','matches Played':280,'avg score':4600}]
f=pd.DataFrame(a)
print(f)
#or
a={'name':['Virat','Rohit','Dhoni'],
'Matches Played':[180,160,170],
'Avg Score':[20,30,280]}
f=pd.DataFrame(a)
print(f)
#2
a=[{'Item':'charger','Cost':180,'Discount':'5%'},
{'Item':'TubeLight','Cost':180,'Discount':'6%'}]
f=pd.DataFrame(a)
print(f)
#OR
a={'Item':['Charger','TubeLight','Bulb'],
'Cost':[23,45,100]}
f=pd.DataFrame(a)
print(f)
'''
#3
'''
a={2015:pd.Series(['78%','33%','67%','98%','60%']),
2016:pd.Series(['78%','33%','67%','98%','60%']),
2017:pd.Series(['78%','63%','67%','38%','60%'])}
f=pd.DataFrame(a,index=[1,2,3,4,5])
print(f)
'''
'''
a={'rollno':pd.Series([1, 2, 3, 4]),
"total":pd.Series([85, 70, 60, 90]),
"Percentage":pd.Series(['85%','70%','60%','90%'])}
x=pd.DataFrame(a)
print(x)
#4.
mn={'Monuments':pd.Series(['Qutab Minar','Humayan Tomb','Lal Quila','Taj Mahal']),
'Year':pd.Series([1193,1524,1863,1630,1887]),
'Built':pd.Series(['Qutab','Bega Begam','Shah jhan','Shahjhan'])}
f=pd.DataFrame(mn,index=[1,2,3])
print(f)
'''
'''
cn = { 'Countries': ['india' , 'pakistan'] ,
'animal':['hen', 'tiger'] ,
'bird':[ 'peacock', 'pidgeon' ],
'currency': ['rupees' , 'dollars'] }
f= pd.DataFrame(cn)
print (f)
a=[{'Country': 'India', 'Animal': 'Tiger',
'Bird': 'Peacock', 'Currency': 'Rupee'},
{'Country': 'A', 'Animal': 'B',
'Bird': 'C', 'Currency': 'D'}]
x=pd.DataFrame(a)
print(x)
'''
#6.
a=[[33,83,49,89],[58,83,49,89],[58,83,49,89],[58,83,49,89],[58,83,49,89]]
m=pd.DataFrame(a,index=['Sharda','Mansi','Kanika','Ramesh','Naina'],
columns=['UT1','Half Yearly','UT2','Final'])
print(m)
#Change the row labels from student name to roll numbers from 1 to 6.
m=m.rename({'Sharda':1,'Mansi':2,
'Kanika':3,'Ramesh':4,'Naina':5},axis="index")
print(m)
#Change the column labels to Term1, Term2, Term3, Term4.
m=m.rename({'UT1':'TERM1','Half Yearly':'TERM2',
'UT2':'TERM3','Final':'TERM4'},axis="columns")
print(m)
#Add a new column Internal Assessment with values ‘A’, ‘A’,’B’,’A’,’C’, ‘B’
m['Grade']=['a','b','c','d','e']
print(m)
#TO ADD NEW ROW
m.loc[6]=[49,65,88,99,'b']
print(m)
#Delete the first row
print("Delete row")
df=m.drop(1,axis=0)
print(df)
#Delete the third column
#print("Delete column")
df1=m.drop('TERM3',axis=1)
print(df1)
print("display 2 row")
#print(m.iloc[2])
print(m.loc[2])
print(m['TERM4']>50)
print(m['Grade']=='a')
print(m.head())
'''
print(m.loc[:,["TERM2","TERM4"]])
#or
print(m[["TERM2","TERM4"]])
print(m)
print(m.iloc[1:5])
print(m.loc[[3,5],["TERM1","TERM2"]])
#print(m.head())
'''
print(m['TERM4']>50) # To show boolean Value
print(m[m['TERM4']<40]) # To show Numeric Value
a={'ID':[101,102,103,104,105,106,107],
'NAME':['JOHN','SMITH','GEORGE','LARA','K GEORGE','JOHSON','LUCY'],
'DEPT':['ENT','ORTHO','MEDICINE','ORTHOPEDIC','CARDIOLOGY','ENT','PSYCHOLOGIST'],'EXPERIENCE':[12,23,22,77,888,999,90]}
f=pd.DataFrame(a,index=[10,20,30,40,50,60,70])
print(f)
print("*"*40)
print(f.iloc[[3,6]])
print(m[[0,2],[1,2]])
Comments
Post a Comment