Pandas documentation lists a bunch of "expanding window functions" :
http://pandas.pydata.org/pandas-docs/version/0.17.0/api.html#standard-expanding-window-functions
But I couldn't figure out what they do from the documentation.
expanding() method is one of the window methods of pandas and it Provides expanding transformations. And it returns a window subclassed for the particular operation. The parameters for this method are min_periods, center, axis, and method. The default value for the min_periods is 1 and it also takes an integer value.
Window functions allow us to perform an operation with a given row's data and data from another row that is a specified number of rows away — this “number of rows away value” is called the window. Window functions allow us to perform computations among the values of a specified column.
Where rolling windows are a fixed size, expanding windows have a fixed starting point, and incorporate new data as it becomes available.
An expanding window refers to a model that calculates a statistic on all available historic data and uses that to make a forecast. It is an expanding window because it grows as more real observations are collected. Two good starting point statistics to calculate are the mean and the median historical observation.
You may want to read this Pandas docs:
A common alternative to rolling statistics is to use an expanding window, which yields the value of the statistic with all the data available up to that point in time.
These follow a similar interface to .rolling, with the .expanding method returning an Expanding object.
As these calculations are a special case of rolling statistics, they are implemented in pandas such that the following two calls are equivalent:
In [96]: df.rolling(window=len(df), min_periods=1).mean()[:5] Out[96]: A B C D 2000-01-01 0.314226 -0.001675 0.071823 0.892566 2000-01-02 0.654522 -0.171495 0.179278 0.853361 2000-01-03 0.708733 -0.064489 -0.238271 1.371111 2000-01-04 0.987613 0.163472 -0.919693 1.566485 2000-01-05 1.426971 0.288267 -1.358877 1.808650 In [97]: df.expanding(min_periods=1).mean()[:5] Out[97]: A B C D 2000-01-01 0.314226 -0.001675 0.071823 0.892566 2000-01-02 0.654522 -0.171495 0.179278 0.853361 2000-01-03 0.708733 -0.064489 -0.238271 1.371111 2000-01-04 0.987613 0.163472 -0.919693 1.566485 2000-01-05 1.426971 0.288267 -1.358877 1.808650
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With