Skip to main content

Get the maximum value from the DataFrame

Pandas DataFrame max() method is used to find the maximum values in the object and returns it.In DatFrame it returns a series with maximum values over specified axis in a dataframe. 

Syntax

DataFrame.max(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Parameters

  • axis:{index (0), columns (1)} 
  • skipna: Exclude null values when computing the result 
  • level: It is by default None. If the axis is multiindex
  • numeric_only: Include float, int, boolean columns. If None is given then use numerical data
  • **kwargs: Any additional keyword argument to be passed.

Return

According to the level specified(either series or dataframe)

1. Find the max value of DataFrame column

Example

import pandas as pd

names = ["John","Jill","Monica","Joey","Alice"]
ages = [22,24,20,24,26]
fees = [True,False,True,True,False]

students = pd.DataFrame({'name':names ,'age':ages,'Fees Submitted':fees})
print(students)

max_value=students.max()
print("max_value along column is:\n",max_value)

Output

     Name  Age  Fees Submitted
0    John   22            True
1    Jill   24           False
2  Monica   20            True
3    Joey   24            True
4   Alice   26           False
max_value along column is:
names    Monica
ages         26
fees       True
dtype: object

2. Find the max value of DataFrame along rows

Example

max_value=students.max(axis=1)
print("max_value along row is:\n",max_value)

Output

max_value along row is:
 0    22.0
1    24.0
2    20.0
3    24.0
4    26.0
dtype: float64

3. Find the max value of complete DataFrame

Example

import pandas as pd

physics=[88,98,67]
chemistry=[56,78,90]
biology=[85,69,93]

students=pd.DataFrame({'Physics':physics,'Chemistry':chemistry,'Biology':biology})
print(students)

max_value=students.max().max()
print("max_value in complete DataFrame is: ",max_value)

Output:

   Physics  Chemistry  Biology
0       88         56       85
1       98         78       69
2       67         90       93

max_value in complete DataFrame is: 98
Submitted by devanshi.srivastava on February 11, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.