Total by group
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` for each region as a Series indexed by region.
What this exercise teaches
groupby splits the rows by region, ["revenue"] picks the column to aggregate, and sum combines each group into one number. The group keys become the index, sorted A to Z.
A hint if you get stuck
groupby(key)[column] picks what to aggregate, then .sum() adds it up per group.
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.