pandas - Pandas 中与 Groupby 的自相关
问题描述
我正在使用 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
功能。
任何人都可以帮忙吗?谢谢!
解决方案
推荐阅读
- dart - 使用 Future.delayed 时的测试中断
- circuit-breaker - 在检查函数中注册失败尝试似乎被计算为双倍
- php - 如何从数据库中获取特定列
- excel - 为行创建键/唯一值
- hyperledger-fabric - 将现有的 Hyperledger Fabric 排序器从单独升级到基于 Kafka
- angular - 没有装饰器的组件的角度依赖注入
- sql - SQL - 想要为每个 IF 条件写入唯一的错误值
- oozie - oozie 4.2.0 版本中的重试最大值
- file - 接受“作为 .BAT 文件中用户的输入?
- java - 从JDK1.8升级到JDK1.11时如何解决“无法解析导入javax.xml.namespace.QName”