Pandas OHLC aggregation on OHLC data

前端 未结 5 1487
刺人心
刺人心 2020-12-22 23:57

I understand that OHLC re-sampling of time series data in Pandas, using one column of data, will work perfectly, for example on the following dataframe:

>         


        
5条回答
  •  太阳男子
    2020-12-23 00:35

    This is similar to the answer you linked, but it a little cleaner, and faster, because it uses the optimized aggregations, rather than lambdas.

    Note that the resample(...).agg(...) syntax requires pandas version 0.18.0.

    In [101]: df.resample('1H').agg({'openbid': 'first', 
                                     'highbid': 'max', 
                                     'lowbid': 'min', 
                                     'closebid': 'last'})
    Out[101]: 
                          lowbid  highbid  closebid  openbid
    ctime                                                   
    2015-09-30 23:00:00  1.11687  1.11712   1.11708    1.117
    

提交回复
热议问题