~/learn/Pandas · Time series
Resampling
Roll daily rows up to weeks, months or quarters.
why this matters
Daily data is noisy. Weekly and monthly rollups are what actually appear in reports and dashboards.
resample is groupby for time. With a datetime index you give it a frequency — D, W, M, Q — and an aggregation.
Try it: Switch to monthly totals with 'ME'.
agg gives several statistics per period at once, and grouping by a second key alongside the frequency produces a per-region time series.
Note
Upsampling to a finer frequency creates gaps — decide explicitly whether to ffill, interpolate or leave them as NaN.
Resample = time-aware groupby
resample("M").sum() ← like GROUP BY month
needs a datetime indexCommon gotcha
resample only works when the index is a datetime. Call set_index('date') first, or pass on='date'.
key takeaways
- resample groups rows by time period.
- The rule string picks the period: D, W, M, Q.
- Follow it with an aggregate like sum or mean.
check your understanding
What does df.resample('W').sum() require?
free practice
Build confidence with a question you can solve without Pro.