在一堆系列上应用autocorr

时间:2018-05-21 08:42:48

标签: python pandas

我有一个包含多个时间序列的数据框:

df.head()
             0         1         2
time                              
0.0   0.365035  0.365035  0.365035
1.0   0.349999  0.349999  0.349999
2.0   0.340998  0.340998  0.340998
3.0   0.333877  0.333877  0.333877
4.0   0.326411  0.326411  0.326411

现在我想计算stdautocorr中的每一个。

我知道我可以单独做到:

df[0].aggregate(['std', 'autocorr'])
Out[10]: 
std         0.081165
autocorr    0.995285

对于std,它有效:

df.unstack().groupby(level=0).aggregate(['std'])
Out[11]: 
        std
0  0.081165
1  0.081165
2  0.081165

但是当我尝试为autocorr做同样的事情时,我得到了

df.unstack().groupby(level=0).aggregate(['autocorr'])
AttributeError: Cannot access callable attribute 'autocorr' of 'SeriesGroupBy' objects, try using the 'apply' method

为什么会这样?什么是正确的方法/解决方法?

1 个答案:

答案 0 :(得分:1)

很可能autocorr未被实现为SeriesGroupBy类的方法。

请改为尝试:

In [15]: df.unstack().groupby(level=0).agg(['std', pd.Series.autocorr])
Out[15]:
        std  autocorr
0  0.014972  0.991893
1  0.014972  0.991893
2  0.014972  0.991893
相关问题