Professional Documents
Culture Documents
More On DataFrame
More On DataFrame
More On DataFrame
data={'RollNo':[1,2,3,4,5],
'Name':['Aditya','Balwant','Chirag','Deepak','Eva'],
'English':[23,18,27,11,17],
'Hindi':[20,1,23,3,21],
'Maths':[28,25,30,7,24]}
df=pd.DataFrame(data)
>>> df
>>> df.iloc[1:3,:]
RollNo Name English Hindi Maths
1 2 Balwant 18 1 25
2 3 Chirag 27 23 30
>>> df['Maths’] += 4
Q. To display the Rollno and Name of all students who secured less than 15 marks
in Maths.
0 False
1 False
2 False
3 True
4 False
0 1
1 2
2 3
3 4
4 5
RollNo Name
0 1 Aditya
1 2 Balwant
2 3 Chirag
3 4 Deepak
4 5 Eva
>>> df[['RollNo','Name','Maths']][df['Maths']<15]
Q. To add and display the total marks i.e., sum of marks secured in English, Hindi
and Maths for all students.
>>> df['Total']=df[['English','Hindi','Maths']].sum(axis=1)
>>> df[['English','Hindi','Maths']].sum(axis=0)
English 96
Hindi 68
Maths 134
dtype: int64
>>> df[['English','Hindi','Maths']].min(axis=0)
English 11
Hindi 1
Maths 11
dtype: int64
>>> df[['English','Hindi','Maths']].min(axis=1)
0 20
1 1
2 23
3 3
4 17
dtype: int64
>>> df.loc[1,'Name']
'Balwant'
>>> df.loc[1,'Hindi']=11
>>> df.loc['A','Hindi']=44