Find the row with the maximum
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
Return the name of the highest-paid employee as a single string, not a Series. Salaries are unique.
What this exercise teaches
idxmax gives the row label where salary peaks, and loc[label, "name"] reads one cell, which is a plain string. Sorting and taking the last row also works but costs a full sort. nlargest(1) keeps the answer wrapped in a Series, so you still need iloc[0] to get the value out.
A hint if you get stuck
Series.idxmax returns the index label of the largest value. Feed that label to loc together with the column you want.
Try it now, free, no account needed
The first 15 tasks on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.
Open this exercise