我尝试使用重采样将1小时数据点转换为4小时数据点,但是最后一个值将始终包含一组不完整的数据,除非是在00:00、04:00、08:00等时间
我考虑过删除整个行,但是这只会有效3/4次,即在4小时打开/关闭时无效
import bitmex
import pandas as pd
client = bitmex.bitmex(test = False, api_key='', api_secret='')
df = pd.DataFrame(client.Trade.Trade_getBucketed(
binSize='1h',
symbol='XBTUSD',
count=750,
reverse=True
).result()[0])
df.set_index(['timestamp'], inplace=True)
df = df.drop(df.columns[[1, 3, 4, 7, 8, 9, 11]], axis=1)
# Set timestamp from close time to open time
df.index = df.index.tz_convert('Etc/GMT+1')
# Convert hourly data to 4 hour
ohlcx = df.resample('4h').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'})
变量“df”处的1小时数据点:
close high low open volume
timestamp
2019-07-16 17:00:00-01:00 9643.0 9900.0 9426.0 9893.0 790487324
2019-07-16 16:00:00-01:00 9893.0 10514.0 9845.5 10513.5 857826447
2019-07-16 15:00:00-01:00 10513.5 10575.0 10417.5 10430.5 164761601
2019-07-16 14:00:00-01:00 10430.5 10512.0 10360.0 10404.5 213959559
2019-07-16 13:00:00-01:00 10404.5 10548.5 10364.5 10500.0 356524833
2019-07-16 12:00:00-01:00 10500.0 10715.0 10435.5 10714.5 339307163
2019-07-16 11:00:00-01:00 10714.5 10789.0 10604.0 10700.0 180303778
2019-07-16 10:00:00-01:00 10700.0 10751.0 10647.5 10693.5 127921432
2019-07-16 09:00:00-01:00 10693.5 10871.0 10655.0 10826.5 244117019
2019-07-16 08:00:00-01:00 10826.5 10869.0 10734.0 10759.0 167522208
当前结果:
open high low close volume
timestamp
2019-07-16 08:00:00-01:00 10759.0 10871.0 10604.0 10714.5 719864437
2019-07-16 12:00:00-01:00 10714.5 10715.0 10360.0 10513.5 1074553156
2019-07-16 16:00:00-01:00 10513.5 10514.0 9426.0 9643.0 1648313771 <--
问题出现在当前输出的最下面一行,其中结果仅使用两个数据点进行计算
如有任何建议,将不胜感激
目前没有回答
相关问题 更多 >
编程相关推荐