Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([[3.0, 2.0],
                   [4.0, np.nan],
                   [2.0, 0.0]],
                   columns=list('XY'))
df
Out[2]:
X Y
0 3.0 2.0
1 4.0 NaN
2 2.0 0.0

By default, iterates over rows and finds the maximum in each column:

In [3]:
df.cummax()
Out[3]:
X Y
0 3.0 2.0
1 4.0 NaN
2 4.0 2.0

To iterate over columns and find the maximum in each row, use axis=1:

In [4]:
df.cummax(axis=1)
Out[4]:
X Y
0 3.0 3.0
1 4.0 NaN
2 2.0 2.0