Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Pandas DataFrame cummin() Method

In this tutorial, we will learn the Python pandas DataFrame.cummin() method. It gives a cumulative minimum over a DataFrame or Series axis. It returns a DataFrame or Series of the same size containing the cumulative minimum.

The below shows the syntax of the Python pandas DataFrame.cummin() method.

Syntax

DataFrame.cummin(axis=None, skipna=True, *args, **kwargs)

Parameters:

axis: {0 or ‘index’, 1 or ‘columns’}, default 0. The index or the name of the axis. 0 is equivalent to None or ‘index’.

skipna: bool, default True. Exclude NA/null values. If an entire row/column is NA, the result will be NA.

*args, **kwargs: Additional keywords have no effect but might be accepted for compatibility with NumPy.

Example 1: Finding the cumulative minimum of the DataFrame

The below example shows how to find the cumulative minimum of the DataFrame over the index axis using the DataFrame.cummin() method.

import pandas as pd  
# Creating the dataframe 
df = pd.DataFrame({"A":[1, 2, 8, 4], "B":[9, 10, 7, 8], "C":[9, 10, 11, 12],"D":[13, 16, 15, 16]})
print(df)
print("-----------Finding cumulative minimum-------")
print(df.cummin(axis = 0))

Once we run the program we will get the following output.


A B C D
0 1 9 9 13
1 2 10 10 16
2 8 7 11 15
3 4 8 12 16
-----------Finding cumulative minimum-------
A B C D
0 1 9 9 13
1 1 9 9 13
2 1 7 9 13
3 1 7 9 13

Example 2: Finding the cumulative minimum of the DataFrame

The below example shows how to find the cumulative minimum of the DataFrame over the column axis using the DataFrame.cummin() method.

import pandas as pd  
# Creating the dataframe 
df = pd.DataFrame({"A":[1, 2, 8, 4], "B":[9, 10, 7, 8], "C":[9, 10, 11, 12],"D":[13, 16, 15, 16]})
print(df)
print("-----------Finding cumulative minimum-------")
print(df.cummin(axis = 1))

Once we run the program we will get the following output.


A B C D
0 1 9 9 13
1 2 10 10 16
2 8 7 11 15
3 4 8 12 16
-----------Finding cumulative minimum-------
A B C D
0 1 1 1 1
1 2 2 2 2
2 8 7 7 7
3 4 4 4 4

Example 3: Finding the cumulative minimum of the DataFrame

The below example shows how to find the cumulative minimum of the DataFrame with null values over the index axis using the DataFrame.cummin() method.

import pandas as pd  
# Creating the dataframe 
df = pd.DataFrame({"A":[1, 2, 8, 4], "B":[9, None, 7, 8], "C":[9, 10, None, 12],"D":[None, 16, 15, 16]}) 
print(df)
print("-----------Finding cumulative minimum-------")
print(df.cummin(skipna=False))

Once we run the program we will get the following output.


A B C D
0 1 9.0 9.0 NaN
1 2 NaN 10.0 16.0
2 8 7.0 NaN 15.0
3 4 8.0 12.0 16.0
-----------Finding cumulative minimum-------
A B C D
0 1 9.0 9.0 NaN
1 1 NaN 9.0 NaN
2 1 NaN NaN NaN
3 1 NaN NaN NaN

Conclusion

In this tutorial, we learned the Python pandas DataFrame.cummin() method. We learned the syntax, parameters and by solving examples we understood the DataFrame.cummin() method.