pandas Rolling Windows: Row-Count vs Time-Offset Behavior on a Gapped Daily Series

This tutorial compares pandas integer-based rolling windows with offset-based windows using a simulated daily mentions series that includes a closure and missing feed days. Offset windows like "7D" shrink when trading days are absent, while integer windows like rolling(5) always span five rows and reach further back in time. The author notes differing defaults: min_periods is 1 for offset windows, while integer windows default to the window size. Six tests were run on pandas 3.0.6 with synthetic data, and the examples are not based on any real stock. Results show that after a closure, the time-based window may contain just one row while the row-based window still averages older values.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in