Pandasdrill

Level 7: Interview cases Exercise 88 of 102

Revenue by country

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

The sales lead asks: which countries bring in the most money? Count completed orders only. Return a DataFrame with the columns `country` and `revenue`, highest revenue first.

What this exercise teaches

Four steps: keep completed orders, merge in the country, add up amount per country, sort. Cancelled orders are the trap. They sit in the same table with a real amount, and nothing fails if you forget to remove them. The total is just wrong.

A hint if you get stuck

The country lives in customers and the money in orders, so the tables have to be joined before you can group.

Try it now, free, no account needed

Your first 8 exercises 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 unlocks every exercise, timed mode and the certificate.

Open this exercise

More exercises in Interview cases