作者bxc (中年鲁蛇联盟)
看板Python
标题[问题] shape不同怎操作
时间Mon Oct 11 12:14:45 2021
取得日线和4H历史资料
2个不同shape的Series怎麽做操作
print(ohlcv_D.close.shape) #(1517,)
print(ohlcv.close.shape) #(36257,)
想把他加到
entries = crossover(macdhist, 0) &
(ohlcv_D.close.shift(1)>ohlcv_D.close.shift(2))
会出现ValueError: shape mismatch: objects cannot be broadcast to a single
shape
ohlcv_D
timestamp
2017-08-17 00:00:00+00:00 4285.08
2017-08-18 00:00:00+00:00 4108.37
2017-08-19 00:00:00+00:00 4139.98
2017-08-20 00:00:00+00:00 4086.29
2017-08-21 00:00:00+00:00 4016.00
ohlcv(4H)
timestamp
2017-08-17 04:00:00+00:00 4308.83
2017-08-17 05:00:00+00:00 4315.32
2017-08-17 06:00:00+00:00 4324.35
2017-08-17 07:00:00+00:00 4349.99
2017-08-17 08:00:00+00:00 4360.69
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.37.0.83 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1633925687.A.548.html
1F:推 TitanEric: 应该是crossover function出来的大小跟要AND的大於结 10/11 12:47
2F:→ TitanEric: 果不一样 这边要检查 10/11 12:47
谢谢回答 4H和1D大小本来就不一样 要怎做处理?
※ 编辑: bxc (114.37.0.83 台湾), 10/11/2021 12:51:37
3F:推 lycantrope: index都已是time series把1D upsampling成4H 10/11 14:05
4F:推 lycantrope: ohlcv_D.resample("4H").ffill() 10/11 16:34
5F:推 lycantrope: 看错了QQ,我的方法不行 10/11 16:45
6F:→ bxc: 谢谢回答 答案是用reindex(index=ohlcv.index, method='ffill 10/11 20:28