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
ts.resample("ME").sum() # month-end totalsts.resample("W")["sales"].mean() # weekly averagets.resample("QE").agg(["sum", "mean"]) # quarterly, multiple stats
Upsampling & filling
ts.resample("D").ffill() # daily, carrying the last value forward
Key takeaways
- 01resample is groupby for time — bucket a series by frequency and aggregate.
- 02Downsampling (daily→monthly) aggregates with sum/mean/agg.
- 03Upsampling creates finer buckets; fill the gaps with ffill or interpolate.
- 04It requires a DatetimeIndex; frequency codes are D/W/ME/QE/YE/h.
