Open In App

How to Get the minimum value from the Pandas dataframe in Python?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to get the minimum value from the Pandas dataframe in Python.

We can get the minimum value by using the min() function

Syntax:

dataframe.min(axis)

where, 

  • axis=0 specifies column
  • axis=1 specifies row

Get minimum value in dataframe row

To get the minimum value in a dataframe row simply call the min() function with axis set to 1.

Syntax:

dataframe.min(axis=1)

Example: Get minimum value in a dataframe row

Python3




# import pandas module
import pandas as pd
 
# create a dataframe
# with 5 rows and 4 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87],
    'age': [11, 23, 23, 21, 21]
})
 
# display dataframe
print(data)
 
# get the minimum in row
data.min(axis=1)


Output:

Get the minimum value in column

To get the minimum value in a column simply call the min() function using axis set to 0.

Syntax:

dataframe.min(axis=0)

Example: Get minimum value in a column

Python3




# import pandas module
import pandas as pd
 
# create a dataframe
# with 5 rows and 4 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87],
    'age': [11, 23, 23, 21, 21]
})
 
# display dataframe
print(data)
 
# get the minimum in column
data.min(axis=0)


Output:

Get the minimum value in a particular column

To get the minimum value in a particular column call the dataframe with the specific column name and min() function.

Syntax:

dataframe['column_name'].min()

Example: Get the minimum value in a particular column 

Python3




# import pandas module
import pandas as pd
 
# create a dataframe
# with 5 rows and 4 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87],
    'age': [11, 23, 23, 21, 21]
})
 
# display dataframe
print(data)
 
# get the minimum in name  column
print(data['name'].min())
 
# get the minimum in subjects  column
print(data['subjects'].min())
 
# get the minimum in age  column
print(data['age'].min())
 
# get the minimum in marks  column
print(data['marks'].min())


Output:



Last Updated : 14 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads