Pandas Min



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.

Minimum values in Pandas requested axis The min function is used to get the minimum of the values for the requested axis. If you want the index of the minimum, use idxmin. This is the equivalent of the numpy.ndarray method argmin. Groupby minimum in pandas python can be accomplished by groupby function. Groupby minimum of multiple column and single column in pandas is accomplished by multiple ways some among them are groupby function and aggregate function. Let’s see how to Groupby single column in pandas – groupby minimum. Df 'Minimum' = df 'B0', 'B1', 'B2'.apply (lambda x: min (x,x,x), axis=1) The target column 'Minimum' is assigned the result of the lambda function based on the selected DF columns 'B0', 'B1', 'B2'. Access elements in a function through the function alias and his new Index (if count of elements is more then one). Find row where values for column is maximum. Complex filter data using query method. Check if one or more columns all exist. Locating the n-smallest and n-largest values. Finding minimum and maximum values. Find index position of minimum and maximum values. Pandas.DataFrame.min ¶ DataFrame.min(axis=None, skipna=None, level=None, numericonly=None,.kwargs) source ¶ Return the minimum of the values over the requested axis. If you want the index of the minimum, use idxmin.

Pandas Min Of Column

Syntax

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.


------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.


------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

Pandas Min Index

Mean

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.


------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

Pandas Max Min

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.

Pandas Minimum


------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.