Python Practice › Pandas Programs › Program 58
Row with the maximum value
Write a pandas program to find the row where a column is largest.
Output
name John salary 65000 Name: 1, dtype: object
Approach
df.loc[df["salary"].idxmax()].
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.