JIYIK CN >

Current Location:Home > Learning > PROGRAM > Python >

Pandas DataFrame DataFrame.min() function

Author:JIYIK Last Updated:2025/04/30 Views:

Python Pandas DataFrame.min() function gets the minimum value of the DataFrame object along the specified axis.


pandas.DataFrame.min()grammar

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

parameter

axis Find the average along the row ( axis=0) or column ( )axis=1
skipna Boolean. Exclude NaNvalue( skipna=True) or include NaNvalue( skipna=False)
level If axis is MultiIndex, find the minimum along a specific level
numeric_only Boolean. For numeric_only=True, only include float, , intand booleancolumns
**kwargs Additional keyword arguments to functions

Return Value

If not specified level, returns the minimum along the requested axis Series, otherwise returns the minimum DataFrame.


Example Code: DataFrame.min()Method to find the minimum value along the column axis

import pandas as pd

df = pd.DataFrame({'X': [1, 2, 2, 3],
                   'Y': [4, 3, 8, 4]})
print("DataFrame:")
print(df)

mins = df.min()

print("Min of Each Column:")
print(mins)

Output:

DataFrame:
   X  Y
0  1  4
1  2  3
2  2  8
3  3  4
Min of Each Column:
X    1
Y    3
dtype: int64

It gets the minimum of the two columns Xand Y, and finally returns a object containing the minimum value of each column Series.

In Pandas, to find the minimum value of a column in a DataFrame, we just call min()the function on that column.

import pandas as pd

df = pd.DataFrame({'X': [1, 2, 2, 3],
                   'Y': [4, 3, 8, 4]})
print("DataFrame:")
print(df)

mins = df["X"].min()

print("Min of Each Column:")
print(mins)

Output:

1DataFrame:
   X  Y
0  1  4
1  2  3
2  2  8
3  3  4
Min of Each Column:
1

It just gives the minimum value of the columns DataFramein .X


Example Code: DataFrame.min()Method to find the minimum value along the row axis

import pandas as pd

df = pd.DataFrame({'X': [1, 2, 7, 5, 10],
                   'Y': [4, 3, 8, 2, 9],
                   'Z': [2, 7, 6, 10, 5]})
print("DataFrame:")
print(df)

mins=df.min(axis=1)

print("Min of Each Row:")
print(mins)

Output:

DataFrame:
    X  Y   Z
0   1  4   2
1   2  3   7
2   7  8   6
3   5  2  10
4  10  9   5
Min of Each Row:
0    1
1    2
2    6
3    2
4    5
dtype: int64

It calculates the minimum value of all rows and returns an Seriesobject containing the average value for each row.


Example code: DataFrame.min()Method to find the minimum value, ignoring NaNthe value

We use skipnathe default value of the parameter, which is , skipna=Trueto find DataFramethe minimum of along the specified axis, ignoring NaNthe value of .

import pandas as pd

df = pd.DataFrame({'X': [1, 2, None, 3],
                   'Y': [4, 3, 7, 4]})
print("DataFrame:")
print(df)

mins=df.min(skipna=True)
print("Min of Columns")
print(mins)

Output:

DataFrame:
     X    Y
0  1.0  4.0
1  2.0  3.0
2  NaN  7.0
3  3.0  4.0
Min of Columns
X    1.0
Y    3.0
dtype: float64

If we set it skipna=True, it will ignore the in DataFrame NaN. It allows us to calculate DataFramethe minimum value of along the column axis, ignoring NaNthe values.

import pandas as pd

df = pd.DataFrame({'X': [1, 2, None, 3],
                   'Y': [4, 3, 7, 4]})
print("DataFrame:")
print(df)

mins=df.min(skipna=False)
print("Min of Columns")
print(mins)

Output:

DataFrame:
     X  Y
0  1.0  4
1  2.0  3
2  NaN  7
3  3.0  4
Min of Columns
X    NaN
Y    3.0
dtype: float64

Here, we get NaNthe value as Xthe mean of column , since Xthere are values ​​in column NaN.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Pandas DataFrame DataFrame.query() function

Publish Date:2025/04/30 Views:107 Category:Python

The pandas.DataFrame.query() method filters the rows of the caller DataFrame using the given query expression. pandas.DataFrame.query() grammar DataFrame . query(expr, inplace = False , ** kwargs) parameter expr Filter rows based on query e

How to Apply a Function to a Column in a Pandas Dataframe

Publish Date:2025/04/30 Views:50 Category:Python

In Pandas, you can transform and manipulate columns and DataFrames using methods apply() such as transform() and . The desired transformation is passed to these methods as a function argument. Each method has its own subtle differences and

Finding the installed version of Pandas

Publish Date:2025/04/12 Views:190 Category:Python

Pandas is one of the commonly used Python libraries for data analysis, and Pandas versions need to be updated regularly. Therefore, other Pandas requirements are incompatible. Let's look at ways to determine the Pandas version and dependenc

KeyError in Pandas

Publish Date:2025/04/12 Views:81 Category:Python

This tutorial explores the concept of KeyError in Pandas. What is Pandas KeyError? While working with Pandas, analysts may encounter multiple errors thrown by the code interpreter. These errors are wide ranging and can help us better invest

Grouping and Sorting in Pandas

Publish Date:2025/04/12 Views:90 Category:Python

This tutorial explored the concept of grouping data in a DataFrame and sorting it in Pandas. Grouping and Sorting DataFrame in Pandas As we know, Pandas is an advanced data analysis tool or package extension in Python. Most of the companies

Plotting Line Graph with Data Points in Pandas

Publish Date:2025/04/12 Views:65 Category:Python

Pandas is an open source data analysis library in Python. It provides many built-in methods to perform operations on numerical data. Data visualization is very popular nowadays and is used to quickly analyze data visually. We can visualize

Converting Timedelta to Int in Pandas

Publish Date:2025/04/12 Views:124 Category:Python

This tutorial will discuss converting a to a using dt the attribute in Pandas . timedelta int Use the Pandas dt attribute to timedelta convert int To timedelta convert to an integer value, we can use the property pandas of the library dt .

Pandas fill NaN values

Publish Date:2025/04/12 Views:93 Category:Python

This tutorial explains how we can use DataFrame.fillna() the method to fill NaN values ​​with specified values. We will use the following DataFrame in this article. import numpy as np import pandas as pd roll_no = [ 501 , 502 , 503 , 50

Pandas Convert String to Number

Publish Date:2025/04/12 Views:147 Category:Python

This tutorial explains how to pandas.to_numeric() convert string values ​​of a Pandas DataFrame into numeric type using the method. import pandas as pd items_df = pd . DataFrame( { "Id" : [ 302 , 504 , 708 , 103 , 343 , 565 ], "Name" :

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial