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)
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.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], [1,7,5,9,0.5], [3,11,13,14,12]], columns=list('ABCDE')) # printing the dataframe print(df) # obtaining the maximum values vertically across rows print(df.max(axis="index")) # obtaining the maximum values horizontally over columns print(df.max(axis="columns"))
pandas
library.df
.df
.max()
function to obtain the maximum values running downwards across the rows (axis 0
). We print the result to the console.max()
function to obtain the maximum values running horizontally across columns (axis 1
). We print the result to the console.RELATED TAGS
CONTRIBUTOR
View all Courses