Pandasdrill

Level 1: Selecting and filtering Exercise 9 of 45 Pro

Top three earners

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 three highest-paid employees with only the `name` and `salary` columns, highest salary first.

What this exercise teaches

nlargest(3, "salary") returns the three rows with the largest salaries in descending order. head(3) without sorting just takes whatever rows happen to come first.

A hint if you get stuck

nlargest(n, column) sorts and takes the top n in one step. head alone only takes the first rows as they are.

This exercise is part of Pro

Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Selecting and filtering