Pandasdrill

Level 3: Aggregating Exercise 45 of 102

Keep the groups above a threshold

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 total `revenue` per region as a Series indexed by region, but only for the regions whose total is above 600.

What this exercise teaches

The condition is about the group total, so it can only be applied after the groupby. Filtering the rows first answers a different question: which single orders are above 600. In SQL terms this is HAVING, not WHERE.

A hint if you get stuck

Aggregate first, then filter the result: the totals are a Series, and a boolean mask on that Series keeps the regions you want.

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 Aggregating