Pivot table with a fill value
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
Build a table of total revenue with one row per region and one column per quarter. Combinations with no sales should show 0, not NaN.
What this exercise teaches
pivot_table groups by the index and columns keys and aggregates the values. Its default aggfunc is mean, so you must ask for sum, and fill_value replaces the empty combinations, such as a region with no first quarter sales.
A hint if you get stuck
pivot_table averages by default. Set aggfunc="sum" and fill_value=0.
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.