What are Pandas "expanding window" functions?

Viewed 24728
3 Answers

To sum up the difference between rolling and expanding function in one line: In rolling function the window size remain constant whereas in the expanding function it changes.

Example: Suppose you want to predict the weather, you have 100 days of data:

  1. Rolling: let's say window size is 10. For first prediction, it will use (the previous) 10 days of data and predict day 11. For next prediction, it will use the 2nd day (data point) to 11th day of data.

  2. Expanding: For first prediction it will use 10 days of data. However, for second prediction it will use 10 + 1 days of data. The window has therefore "expanded."

    • Window size expands continuously in later method.

Code example:

sums = series.expanding(min_periods=2).sum()

series contains data of number of previously downloaded apps over time series. Above written code line sum all the number of downloaded apps till that time.

Note: min_periods=2 means that we need at least 2 previous data points to aggregate over. Our aggregate here is the sum.

Related