A join that inflates the total
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 price list was exported twice for some products, so `prices` has repeated rows. What is the total revenue across all order lines, where revenue is `qty` times `price`? Return a single number.
What this exercise teaches
A merge returns one row for every matching pair, so a product that appears twice in prices doubles each of its order lines and the total is too high without any error. Removing the repeated rows first keeps one price per product. In real work, merge(..., validate="many_to_one") would have raised an error at once.
A hint if you get stuck
Check how many rows the merge returns compared with items. If it returns more, a key is repeated in the lookup table.
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
- Revenue by country
- 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
- 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