Monthly totals with resample
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
Total `amount` per calendar month with `resample`, labeling each month by its first day (rule "MS"). Months with no transactions must appear with a total of 0.
What this exercise teaches
resample groups rows into regular time buckets and includes empty buckets, so a month with no sales shows 0. Grouping by the month number would silently skip it.
A hint if you get stuck
resample works on a datetime index, or pass on="date". "MS" means month start.
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.