Python Practice › Pandas Programs › Program 58

Row with the maximum value

EasyPandas Programs · 58 of 95

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

Advertisement
Output
name       John
salary    65000
Name: 1, dtype: object

Approach

  1. df.loc[df["salary"].idxmax()].

Solution

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

Learn the concept

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

More pandas programs

← All 95 Pandas Programs