Signup/Sign In

Pandas DataFrame min() Method

In this tutorial, we will learn the Python pandas DataFrame.min() method. This method can be used to get the minimum of the values over the requested axis. It returns Series and if the level is specified, it returns the DataFrame.

The below is the syntax of the DataFrame.min() method.

Syntax

DataFrame.min(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Parameters

axis: It represents index or column axis, '0' for index and '1' for the column. When the axis=0, method applied over the index axis and when the axis=1 method applied over the column axis.

skipna: bool(True or False). The default value is None. If this parameter is True, it excludes all NA/null values when computing the result.

level: It represents the int or level name, the default value is None. If the axis is a MultiIndex (hierarchical), count along with a particular level, collapsing into a Series.

numeric_only: bool(True or False), the default is None. If this parameter is True, it includes only float, int, boolean columns.

**kwargs: Additional keyword arguments to be passed to the method.

Example 1: Find minimum values using the DataFrame.min() Method

Let's create a DataFrame and get the minimum value over the index axis by assigning parameters axis=0 in the DataFrame.min() method. See the below example.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df = pd.DataFrame({"A":[0,52,78],"B":[77,45,96],"C":[16,23,135],"D":[17, 22, 56]}) 
print("------The DataFrame is------")
print(df)
print("---------------------------")
print(df.min(axis=0))


------The DataFrame is------
A B C D
0 0 77 16 17
1 52 45 23 22
2 78 96 135 56
---------------------------
A 0
B 45
C 16
D 17
dtype: int64

Example 2: Find minimum values using the DataFrame.min() Method

Let's create a DataFrame and get the minimum value over the column axis by assigning parameter axis=1 in the DataFrame.min() method. The below example shows the same.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df = pd.DataFrame({"A":[0,52,78],"B":[77,45,96],"C":[16,23,135],"D":[17, 22, 56]}) 
print("------The DataFrame is------")
print(df)
print("---------------------------")
print(df.min(axis=1))


------The DataFrame is------
A B C D
0 0 77 16 17
1 52 45 23 22
2 78 96 135 56
---------------------------
0 0
1 22
2 56
dtype: int64

Example 3: Find minimum values using the DataFrame.min() Method

Here, we are creating a DataFrame with null values and getting the minimum value over the index axis including null values by passing parameter skipna=False in the DataFrame.min() method. It includes all NA/null values when computing the results. The below example shows the same.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df = pd.DataFrame({"A":[0,None,78],"B":[77,45,None],"C":[16,23,None],"D":[17, 22, 56]}) 
print("------The DataFrame is------")
print(df)
print("---------------------------")
print(df.min(axis=0,skipna=False))


------The DataFrame is------
A B C D
0 0.0 77.0 16.0 17
1 NaN 45.0 23.0 22
2 78.0 NaN NaN 56
---------------------------
A NaN
B NaN
C NaN
D 17.0
dtype: float64

Example 4: Find minimum values using the DataFrame.min() Method

Let's create a DataFrame with null values and get the minimum value over the index axis excluding null values by passing parameter skipna=True in the DataFrame.min() method. It excludes all NA/null values when computing the results. The below example shows the same.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df = pd.DataFrame({"A":[0,None,78],"B":[77,45,None],"C":[16,23,None],"D":[17, 22, 56]}) 
print("------The DataFrame is------")
print(df)
print("---------------------------")
print(df.min(axis=0,skipna=True))


------The DataFrame is------
A B C D
0 0.0 77.0 16.0 17
1 NaN 45.0 23.0 22
2 78.0 NaN NaN 56
---------------------------
A 0.0
B 45.0
C 16.0
D 17.0
dtype: float64

Conclusion

In this tutorial, we learned the Python pandas DataFrame.min() method. We learned the syntax, parameters and applied it on the DataFrame to understand the DataFrame.min() method.



About the author:
I like writing about Python, and frameworks like Pandas, Numpy, Scikit, etc. I am still learning Python. I like sharing what I learn with others through my content.