Group by two keys
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 total revenue for every region and quarter combination as a DataFrame with columns `region`, `quarter` and `revenue`.
What this exercise teaches
Grouping by a list makes one group per combination that appears in the data. With as_index=False both keys stay as columns, region first because it is listed first.
A hint if you get stuck
Pass a list of columns to groupby. The order of the list sets the column order and the sort order.
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.