我正在使用Python处理面板数据集。数据框看起来像
stock date time spread
VOD 01-01 9:05 0.01
VOD 01-01 9:12 0.03
VOD 01-01 10:04 0.02
VOD 01-01 10:15 0.01
VOD 01-01 10:25 0.03
VOD 01-01 11:04 0.02
VOD 01-02 9:04 0.02
... ... ... ....
BAT 01-01 13:05 0.04
BAT 01-02 9:07 0.05
BAT 01-02 9:10 0.06
我打算得到点差的股票日自相关表
stock date autocorrelation
VOD 01-01 0.52
VOD 01-02 0.32
BAT 01-01 0.23
BAT 01-02 0.54
... ... ...
我尝试过
want=df.groupby(['stock','date'])['spread'].autocorr(lag=1)
但是,系统给了我:
AttributeError: Cannot access callable attribute 'autocorr' of 'SeriesGroupBy' objects, try using the 'apply' method.
似乎我不能同时使用Groupby
和autocorr
函数。
有人可以帮忙吗?谢谢!