Skip to main content
Albero Academy

Resampling

Change the frequency of a time series — daily to monthly and back.

Time Series & Advanced8 min

Resampling is groupby for time: it buckets a time series into a new frequency and aggregates each bucket. It's how you turn daily data into monthly totals, or fill gaps in an irregular series.

Downsampling

daily → monthly
ts.resample("ME").sum() # month-end totals
ts.resample("W")["sales"].mean() # weekly average
ts.resample("QE").agg(["sum", "mean"]) # quarterly, multiple stats

Upsampling & filling

finer frequency
ts.resample("D").ffill() # daily, carrying the last value forward

Key takeaways

  1. 01resample is groupby for time — bucket a series by frequency and aggregate.
  2. 02Downsampling (daily→monthly) aggregates with sum/mean/agg.
  3. 03Upsampling creates finer buckets; fill the gaps with ffill or interpolate.
  4. 04It requires a DatetimeIndex; frequency codes are D/W/ME/QE/YE/h.

Finished this chapter?

Mark it complete to track your progress through Pandas.