When using pandas stats.moments.rolling_mean(array,window) function I noticed that putting an extra argument changes the output, and is only padded with nans in the beginning not the end.
In[1]: import pandas as pd
In[2]: pd.stats.moments.rolling_mean(np.arange(12),6)
Out[2]:
array([ nan, nan, nan, nan, nan, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
8.5])
I expected there to be 6 nans: 3 at the beginning and 3 at the end.
What am I missing here?
/M
The pandas implementation uses a rolling window of the previous n values, which is how it’s usually done in finance (see this Wikipedia entry for simple moving average).
I guess it would be nice to have the option to specify whether the values should be taken from either side or just use previous values – you can raise an issue on GitHub.
len(np.arange(12))andlen(pd.stats.moments.rolling_mean(np.arange(12),6))both equal 12 as I would have expected – what result were you expecting?