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 exerciseMore exercises in Interview cases
- Repeat customers
- Month over month revenue growth
- Best-selling product in each region
- Customers who never ordered
- Average order value by segment
- New customers per month
- Second order within 30 days
- A join that inflates the total
- Top three customers and their share
- Value lost to cancellations
- Average days between orders
- Messy export: clean, then total
- New and returning customers per month
- A conversion funnel