Page 85 - IPP-12-2024
P. 85
print(df['Marks'])
print("Maximum Marks : ", df['Marks'].max())
print("Printing According to Condition")
print(df[df.Marks>70])
print("Printing the row with maximum marks")
print(df[df.Marks==df.Marks.max()])
print("Printing specific columns with maximum Marks")
print(df[['Name','Marks']][df.Marks==df.Marks.max()])
print("According to index")
print(df.loc[3])
print("Changing of Index")
df.set_index('Scno',inplace=True)
print(df)
print("Searching according to new index")
print(df.loc[4862])
print("Resetting the Index")
df.reset_index(inplace=True)
print(df)
print("Sorting")
print(df.sort_values(by=['Marks'],ascending=False))
print("Sorting on Multiple Columns")
print(df.sort_values(by=['Class', 'Section'],ascending=True))
print("Sorting on Multiple Columns one in ascending, another in
descending")
print(df.sort_values(by=['Marks','Name'],ascending=[False,True]))
print("Sum Operations on Data Frame")
print(df['Marks'].sum())
print("Group By Operations")
print(df. groupby('Class')['Marks'].sum())
Output:
To display selected number of rows from beginning
Scno Name Class Section Marks
0 1 Mohit 10 A 90
1 2 Rachit 11 B 89
2 3 Pragiti 12 C 78
Scno Name Class Section Marks
0 1 Mohit 10 A 90
1 2 Rachit 11 B 89
2 3 Pragiti 12 C 78
3 4 Samridhi 10 A 65
4 5 Yukti 12 D 67
5 6 Hiten 11 B 99
6 7 Yuvan 10 D 94
7 8 Sahib 9 C 80
8 9 Diviyansh 10 A 58
9 10 Mehak 12 C 88
Number of Rows and Columns