How to resample pandas df tick data to 5 min OHLC data

前端 未结 1 574
面向向阳花
面向向阳花 2021-02-06 08:40

I have a pandas df \'instr_bar\' with tick data as follows:

time
2016-07-29 16:07:24     5.72
2016-07-29 16:07:24     5.72
2016-07-29 16:07:24     5.72
2016-07-2         


        
相关标签:
1条回答
  • 2021-02-06 09:25

    try bfill():

    instr_bar = instr_bar.resample('5T').ohlc().bfill()
    

    or ffill():

    instr_bar = instr_bar.resample('5T').ohlc().ffill()
    

    depending on what do you want to achieve

    if you want to filter rows by time you can use between_time() method:

    instr_bar.between_time('09:00', '16:30')
    

    altogether:

    instr_bar = instr_bar.resample('5T').ohlc().ffill().between_time('09:00', '16:30')
    
    0 讨论(0)
提交回复
热议问题