Python Practice › Pandas Programs › Program 59

Row with the minimum value

EasyPandas Programs · 59 of 95

Write a pandas program to find the row where a column is smallest.

Advertisement
Output
name       Alex
salary    50000
Name: 0, dtype: object

Approach

  1. idxmin().

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "salary": [50000, 65000, 63000, 59000]})print(df.loc[df["salary"].idxmin()])
Output
name       Alex
salary    50000
Name: 0, dtype: object
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs