小编use*_*187的帖子

大熊猫OHLC聚合OHLC数据

据我所知,OHLC使用一列数据对Pandas中的时间序列数据进行重新采样将完美地工作,例如在以下数据帧上:

>>df
ctime       openbid
1443654000  1.11700
1443654060  1.11700
...

df['ctime']  = pd.to_datetime(df['ctime'], unit='s')
df           = df.set_index('ctime')
df.resample('1H',  how='ohlc', axis=0, fill_method='bfill')


>>>
                     open     high     low       close
ctime                                                   
2015-09-30 23:00:00  1.11700  1.11700  1.11687   1.11697
2015-09-30 24:00:00  1.11700  1.11712  1.11697   1.11697
...
Run Code Online (Sandbox Code Playgroud)

但是如果数据已经是OHLC格式,我该怎么办?根据我的收集,API的OHLC方法为每列计算OHLC切片,因此如果我的数据采用以下格式:

             ctime  openbid  highbid   lowbid  closebid
0       1443654000  1.11700  1.11700  1.11687   1.11697
1       1443654060  1.11700  1.11712  1.11697   1.11697
2       1443654120  1.11701  1.11708  1.11699   1.11708
Run Code Online (Sandbox Code Playgroud)

当我尝试重新采样时,我会为每个列获得一个OHLC,如下所示:

                     openbid                             highbid           \
                        open     high      low    close     open     high   
ctime                                                                       
2015-09-30 23:00:00  1.11700  1.11700  1.11700  1.11700 …
Run Code Online (Sandbox Code Playgroud)

python resampling dataframe python-2.7 pandas

28
推荐指数
3
解决办法
2万
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1

python-2.7 ×1

resampling ×1