Pandasdrill

Level 4: Combining and reshaping Exercise 32 of 45 Pro

Merge twice, then aggregate

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

Compute total spend (`qty * price`) per customer city, using only orders that match both a customer and a product. Return a Series indexed by city.

What this exercise teaches

Each merge adds the columns you need: city from customers and price from products. Inner joins drop orders that cannot be priced or placed, and the groupby sums spend per city.

A hint if you get stuck

Chain two merges, add a spend column, then group by city.

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 Combining and reshaping