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