0

Just looking for some help to resample my 1min OHLCV data to 5min. I have used this answer to guide me, however I seem to be coming up with an error stating: {Key error Timestamps}

import pandas as pd

df= pd.read_csv("/Users/dstan1/Downloads/fut01.csv",
                names=['timestamps','open','high','low','close','volume'])

df.set_index('timestamps',inplace=True)

ohlc_dict = {
    'open':'first',
    'high':'max',
    'low':'min',
    'close':'last',
    'volume':'sum'
    }

df['timestamps'] = pd.to_datetime(df['timestamps'])
df.set_index('timestamps', inplace=True)

df.resample('5T', how=ohlc_dict)

print (df)

Data attached

Wanting to turn it into (used from the referenced example).

                           high     close      open       low    volume
timestamps                                                           
2016-08-09 12:35:00 536.7849  536.7849  536.7841  536.6141  0.656000
2016-08-09 12:40:00 536.6749  534.8416  536.6749  534.1801  2.277200
2016-08-09 12:45:00 538.5999  537.7289  534.8131  534.2303  2.971872
2016-08-09 12:50:00 539.2199  539.2199  537.9829  537.9829  1.115219

Any help or guidance would be greatly appreciated.

Dstan1
  • 1
  • 1
  • apologies, the table datasets at the bottom should be in the same order as the above (open, high, low, close, volume) my mistake sorry – Dstan1 Jun 29 '21 at 09:11
  • Can you clarify where you are getting the error? FYI: When you set an index, the field no longer exists, and since you are setting the index twice, that may be causing your issue, but we would need to know more about where the error occurs. – Eliot K Jun 29 '21 at 20:05
  • thanks for that. Sure. Getting ther error at: – Dstan1 Jun 30 '21 at 02:25

0 Answers0