import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
'ID':[1,2,3,4,5,6],
'MATH':[80,40,70,70,70,30],
'ENGLISH':[80,70,40,50,60,30]}
my_data = pd.DataFrame(data=my_dict)
print(my_data.max())
Output
NAME Ron
ID 6
MATH 80
ENGLISH 80
What is the highest mark in MATH ?
print(my_data['MATH'].max()) # 80
We can get the row or details of the record who got maximum mark in MATH
print(my_data[my_data['MATH'].max()==my_data['MATH']])
Output is here
NAME ID MATH ENGLISH
0 Ravi 1 80 80
We will use option axis=0 ( default ) by adding to above code.print(my_data.max(axis=1))
Output is here
0 80
1 70
2 70
3 70
4 70
5 30
import pandas as pd
my_dict=pd.MultiIndex.from_arrays(
[[1,2,3,4,5,6],
[80,40,70,70,70,30],
[80,70,40,50,60,30]],
names=['id','math','eng'])
my_data = pd.Series([4, 2, 0, 8,3,4], name='marks', index=my_dict)
print(my_data.max(level='math'))
Output
math
80 4
40 2
70 8
30 4
import numpy as np
import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
'ID':[1,2,3,4,5,6],
'MATH':[80,40,70,70,70,30],
'ENGLISH':[80,70,np.nan,50,60,30]}
my_data = pd.DataFrame(data=my_dict)
print(my_data.max(skipna=True))
Output
NAME Ron
ID 6
MATH 80
ENGLISH 80
print(my_data.max(numeric_only=False))
Output is here
NAME Ron
ID 6
MATH 80
ENGLISH 80
Pandas
Data Analysis
min
sum
len
std
Filtering of Data
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.