Python - Calculate the minimum of column values of a Pandas DataFrame



To get the minimum of column values, use the min() function. At first, import the required Pandas library −

import pandas as pd

Now, create a DataFrame with two columns −

dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'],"Units": [100, 150, 110, 80, 110, 90] } )

Finding the minimum value of a single column “Units” using min() −

print"Minimum Units from DataFrame1 = ",dataFrame1['Units'].min() 

In the same way, we have calculated the minimum value from the 2nd DataFrame.

Example

Following is the complete code −

import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'],"Units": [100, 150, 110, 80, 110, 90] } ) print"DataFrame1 ...\n",dataFrame1 # Finding minimum value of a single column "Units" print"Minimum Units from DataFrame1 = ",dataFrame1['Units'].min() # Create DataFrame2 dataFrame2 = pd.DataFrame(    {       "Product": ['TV', 'PenDrive', 'HeadPhone', 'EarPhone', 'HDD', 'SSD'],"Price": [8000, 500, 3000, 1500, 3000, 4000] } ) print"\nDataFrame2 ...\n",dataFrame2 # Finding minimum value of a single column "Price" print"Minimum Price from DataFrame2 = ",dataFrame2['Price'].min()

Output

This will produce the following output −

DataFrame1 ...        Car   Units 0      BMW     100 1    Lexus     150 2     Audi     110 3    Tesla      80 4  Bentley     110 5   Jaguar      90 Minimum Units from DataFrame1 = 80 DataFrame2 ...    Price   Product 0   8000         TV 1    500 PenDrive 2   3000 HeadPhone 3   1500 EarPhone 4   3000 HDD 5   4000 SSD Minimum Price from DataFrame2 = 500
Updated on: 2021-09-22T11:14:09+05:30

569 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements