How to Get the maximum value from the Pandas dataframe in Python?
Last Updated :
28 Nov, 2021
Python Pandas max() function returns the maximum of the values over the requested axis.
Syntax: dataframe.max(axis)
where,
- axis=0 specifies column
- axis=1 specifies row
Example 1: Get maximum value in dataframe row
To get the maximum value in a dataframe row simply call the max() function with axis set to 1.
Syntax: dataframe.max(axis=1)
Python3
import pandas as pd
data = pd.DataFrame({
'name' : [ 'sravan' , 'ojsawi' , 'bobby' ,
'rohith' , 'gnanesh' ],
'subjects' : [ 'java' , 'php' , 'html/css' ,
'python' , 'R' ],
'marks' : [ 98 , 90 , 78 , 91 , 87 ],
'age' : [ 11 , 23 , 23 , 21 , 21 ]
})
print (data)
data. max (axis = 1 )
|
Output:
Example 2: Get the maximum value in column
To get the maximum value in a column simply call the max() function using the axis set to 0.
Syntax: dataframe.max(axis=0)
Python3
import pandas as pd
data = pd.DataFrame({
'name' : [ 'sravan' , 'ojsawi' , 'bobby' ,
'rohith' , 'gnanesh' ],
'subjects' : [ 'java' , 'php' , 'html/css' ,
'python' , 'R' ],
'marks' : [ 98 , 90 , 78 , 91 , 87 ],
'age' : [ 11 , 23 , 23 , 21 , 21 ]
})
print (data)
data. max (axis = 0 )
|
Output:
Example 3: Get the maximum value in a particular column
To get the maximum value in a particular column call the dataframe with the specific column name and max() function.
Syntax: dataframe[‘column_name’].max()
Python3
import pandas as pd
data = pd.DataFrame({
'name' : [ 'sravan' , 'ojsawi' , 'bobby' ,
'rohith' , 'gnanesh' ],
'subjects' : [ 'java' , 'php' , 'html/css' ,
'python' , 'R' ],
'marks' : [ 98 , 90 , 78 , 91 , 87 ],
'age' : [ 11 , 23 , 23 , 21 , 21 ]
})
print (data)
print (data[ 'name' ]. max ())
print (data[ 'subjects' ]. max ())
print (data[ 'age' ]. max ())
print (data[ 'marks' ]. max ())
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...