Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to obtain the maximum value of an axis of a pandas DataFrame

Onyejiaku Theophilus Chidalu


The max() function is used to return the maximum values of a specified axis.

Note: Axis here represents the rows and columns of the DataFrame. An axis with a value of '0' indicate the axes running vertically downwards across a row, while a value of '1' indicates the axes running running horizontally across a column.


DataFrame.max(axis=None, skipna=True, *args, **kwargs)
Syntax for the cummax() function in Pandas


  • axis: This represents the name for the row (designated as 0 or 'index') or the column (designated as 1 or columns) axis.
  • skipna: This takes a Boolean value indicating if null values are to be excluded. This is an optional parameter.
  • level: This takes an integer or a level name specifying the count along a particular level.
  • numeric_only: This takes a boolean value indicating whether to include only float, integer, or boolean columns.
  • **kwargs: This is a keyword that has no effect but may be accepted for compatibility with NumPy. This is an optional parameter.

Return value

This function returns a Series or DataFrame object showing the maximum values in the specified axis.


# A code to illustrate the max() function in Pandas

# importing the pandas library
import pandas as pd

# creating a dataframe
df = pd.DataFrame([[5,10,4,15,3],
# printing the dataframe

# obtaining the maximum values vertically across rows

# obtaining the maximum values horizontally over columns
Implementing the max() function


  • Line 4 : We import the pandas library.
  • Lines 7–10: We create a DataFrame, df.
  • Line 12: We print the DataFrame, df.
  • Line 15: We use the max() function to obtain the maximum values running downwards across the rows (axis 0). We print the result to the console.
  • Line 18: We use the max() function to obtain the maximum values running horizontally across columns (axis 1). We print the result to the console.




Onyejiaku Theophilus Chidalu

View all Courses

Keep Exploring