我想把1h-OHLC数据转换成xh-OHLC数据。我正在使用重采样方法,就像在类似的线程中提出的一样,但它不会导致想要的结果。数据:
open high low close Volume USD
date
2021-07-10 21:00:00 132.060 133.350 131.885 133.195 259057.35815
2021-07-10 22:00:00 133.195 134.160 132.885 134.045 813078.76500
2021-07-10 23:00:00 134.045 134.620 133.690 133.995 338032.62200
2021-07-11 00:00:00 133.995 135.515 133.745 134.390 560713.74425
2h的重采样方法:
df.resample('2H').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'Volume USD': 'sum'
})
结果是:
open high low close Volume USD
date
2021-07-10 20:00:00 132.060 133.350 131.885 133.195 2.590574e+05
2021-07-10 22:00:00 133.195 134.620 132.885 133.995 1.151111e+06
2021-07-11 00:00:00 133.995 135.515 133.745 134.390 5.607137e+05
我想要的是一个从22:00开始的数据帧,其中包含21:00和22:00的数据,第二行包含00:00,使用23:00和00.00的数据
非常感谢你的帮助
要获得所需结果,请将
resample
的closed
和label
参数设置为right
:closed
参数控制区间的哪一端是包含的,而label
参数控制区间的哪一端出现在结果索引上right
和left
分别表示间隔的结束和开始相关问题 更多 >
编程相关推荐