We use the cummax()
function of a DataFrame
object to obtain the cumulative maximum over its axis.
Axis here represents the row and column of the DataFrame. The axis with a value of
'0'
indicates the axes that run vertically downwards across a row, while a value of'1'
shows the axes that run horizontally across a column.
The cummax()
function takes the syntax shown below:
DataFrame.cummax(axis=None, skipna=True, *args, **kwargs)
The cummax()
function takes the following parameter values:
axis
: This represents the name for the row (designated as 0
or 'index'
) or the column (designated as 1
or columns
) axis.skipna
(optional): This takes a Boolean value indicating if NA or null values are to be excluded or not.args
, **kwargs
(optional): These are keywords that have no effect but may be accepted for compatibility with NumPy.The cummax()
function returns a Series
or DataFrame
object showing the cumulative maximum in the axis.
# A code to illustrate the cummax() 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 cummulative maximum vertically across rows print(df.cummax(axis="index")) # obtaining the cummulative maximum horizontally over columns print(df.cummax(axis="columns"))
df
.df
.0
). We print the result to the console.1
). We print the result to the console.RELATED TAGS
CONTRIBUTOR
View all Courses