Rolling and Expanding in Python

From the Pandas cheat sheet ยท Windows and Time Series ยท verified Aug 2026

Rolling and Expanding

Calculate statistics across moving or cumulative windows.

python
df["moving_avg"] = df["value"].rolling(7, min_periods=1).mean()
๐Ÿ“Œ Sort time data before window operations
๐Ÿ’ก Offset windows handle uneven timestamps
๐Ÿ” expanding uses all observations to date
๐ŸŽฏ Set min_periods for early-window behavior
rollingwindowtime-series

Continue with Pandas

Save the full cheat sheet or work through every related task.

Back to the full Pandas cheat sheet