小编jes*_*ern的帖子

使用大熊猫将贸易数据重新采样到OHLCV

我在pandas DataFrame中有历史交易数据,包含价格和交易量列,由DateTimeIndex索引.

例如:

>>> print df.tail()
                             price  volume
2014-01-15 14:29:54+00:00  949.975    0.01
2014-01-15 14:29:59+00:00  941.370    0.01
2014-01-15 14:30:17+00:00  949.975    0.01
2014-01-15 14:30:24+00:00  941.370    0.01
2014-01-15 14:30:36+00:00  949.975    0.01
Run Code Online (Sandbox Code Playgroud)

现在,我可以将其重新采样到OHLC数据中使用df.resample(freq, how={'price': 'ohlc'}),这很好,但我也想要包含音量.

当我尝试时df.resample(freq, how={'price': 'ohlc', 'volume': 'sum'}),我得到:

ValueError: Shape of passed values is (2,), indices imply (2, 95)

我不太确定我的数据集有什么问题,或者为什么会失败.任何人都可以帮忙解释一下吗?非常感激.

python pandas

10
推荐指数
1
解决办法
7013
查看次数

标签 统计

pandas ×1

python ×1