+2 votes
in Programming Languages by (17.9k points)
I want to find the cumulative maximum along a given axis of a pandas dataframe. Which function should I use for it?

1 Answer

+1 vote
by (28.5k points)

You can use the cummax() of the Pandas. It returns a cumulative maximum over a DataFrame or Series axis.

Here is an example:

>>> import pandas as pd
>>> df = pd.DataFrame({'A':[1,4,3,2,5], 'B':[10,23,11,12,25]})
>>> df.cummax(axis=1)
   A   B
0  1  10
1  4  23
2  3  11
3  2  12
4  5  25
>>> df.cummax(axis=0)
   A   B
0  1  10
1  4  23
2  4  23
3  4  23
4  5  25
>>>


...