~/learn/Pandas · Time series

Resampling

Roll daily rows up to weeks, months or quarters.

9 min readlesson 10 of 13resamplemonthly

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.

python · editable
loading editor…

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.

python · editable
loading editor…

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 index

Common 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.