Resampling a time series in Python
resample is groupby for time: pick a frequency, pick an aggregate.
import pandas as pd
index = pd.date_range("2026-07-01", periods=10, freq="D")
runs = pd.Series(range(90, 100), index=index, name="tpm")
print(runs.resample("W").mean().round(1))
print(runs.resample("3D").agg(["min", "max"]))
print(runs.resample("ME").sum())
How it works
MEis month end,Wweek,Dday — the alias decides the bucket.- Empty buckets appear, so decide what filling them means.
asfreqreindexes without aggregating.
Keywords and builtins used here
asprintrange
The run, in numbers
- Lines
- 8
- Characters to type
- 259
- Tokens
- 106
- Three-star pace
- 110 tpm
At the three-star pace of 110 tokens a minute, this run takes about 58 seconds.
Step 2 of 3 in Time series, step 24 of 26 in pandas.