Get the minimum value of column in python pandas

Get the minimum value of column in python pandas : In this section we will learn How to get the minimum value of all the columns in dataframe of python pandas. How to get the minimum value of a specific column or a series using min() function.  

Syntax of Pandas Min() Function:

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

 

axis  0 – Rows wise operation
1- Columns wise operation
skipna  Exclude NA/null values when computing the result
level  If the axis is a Multi index (hierarchical), count along a particular level, collapsing into a Series
numeric_only  Include only float, int, boolean columns. If None, will attempt to use everything

We will looking at an example on

  • How to get Column wise minimum value of all the column.
  • Get minimum value of a specific column by name
  • Get minimum value of series in pandas python
  • Get minimum value of a specific column by index

 

Create Dataframe:


import pandas as pd
import numpy as np

#Create a DataFrame
d = {
'Name':['Alisa','Bobby','jodha','jack','raghu','Cathrine',
'Alisa','Bobby','kumar','Alisa','Alex','Cathrine'],
'Age':[26,24,23,22,23,24,26,24,22,23,24,24],

'Score':[85,63,55,74,31,77,85,63,42,62,89,77]}

df = pd.DataFrame(d,columns=['Name','Age','Score'])
df

So the resultant dataframe will be

Get the minimum value of column in dataframe –python pandas 1

 

Get the minimum value of all the column in python pandas:


# get the minimum values of all the column in dataframe

df.min()

This gives the list of all the column names and its minimum value, so the output will be

Get the minimum value of column in dataframe –python pandas 2

 

Get the minimum value of a specific column in python pandas:

Example 1:


# get the minimum value of the column 'Age'

df['Age'].min()

This gives the minimum value of column Age so the output will be

22

 

Example 2:


# get the minimum value of the column 'Name'

df['Name'].min()

This gives the minimum value of column Name so the output will be

‘Alex’

 

 

Get the minimum value of a specific column in pandas by column index:

 # get minimum value of the column by column index

df.iloc[:, [1]].min()

df.iloc[] gets the column index as input here column index 1 is passed which is 2nd column (“Age” column) , minimum value of the 2nd  column is calculated using min() function as shown.

Minimum value of the column in pandas 11

 

 

Get Minimum value of the series in pandas :

Lastly we would see how to calculate the minimum value of a series in pandas by using min() function . First lets create a series of alphabets as shown below

### Create a series 

import pandas as pd
import numpy as np
data = np.array(['a','b','c','d','e','f'])
ser = pd.Series(data,index=[1000,1001,1002,1003,1004,1005])

created series is

Minimum value of the column in pandas 12

Minimum value of a series is calculated using series.min() function as shown below

### Calculate minimum value of a series 

ser.min()

so the resultant min value of the series is

‘ a ‘

 

previous-small Get the minimum value of column in dataframe –python pandas                                                                                                           next_small Get the minimum value of column in dataframe –python pandas

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts