Pandas DataFrame | cummax method
Start your free 7-days trial now!
Pandas DataFrame.cummax(~) method computes the cumulative maximum along the row or column of the source DataFrame.
Parameters
1. axislink | int or string | optional
Whether to compute the cumulative maximum along the row or the column:
Axis | Description |
|---|---|
| Compute the cumulative maximum of each column. |
| Compute the cumulative maximum of each row. |
By default, axis=0.
2. skipnalink | boolean | optional
Whether or not to ignore NaN. By default, skipna=True.
Return Value
A DataFrame holding the cumulative maximum of the row or column values.
Examples
Consider the following DataFrame:
df
A B C0 3 7 31 2 6 52 4 2 6
Cumulative maximum of each column
To compute the cumulative maximum for each column:
df.cummax()
A B C0 3 7 31 3 7 52 4 7 6
Cumulative maximum of each row
To compute the cumulative maximum for each row:
df.cummax(axis=1)
A B C0 3 7 71 2 6 62 4 4 6
Dealing with missing values
Consider the following DataFrame with a missing value:
df
A0 5.01 NaN2 3.0
By default, skipna=True, which means that missing values are ignored:
df.cummax() # skipna=True
A0 5.01 NaN2 5.0
To take into account missing values:
df.cummax(skipna=False)
A0 5.01 NaN2 NaN
Here, notice how we end up with a NaN after the first NaN.