When using pandas' resample
function on a DataFrame in order to convert tick data to OHLCV, a resampling error is encountered.
How should we solve the error?
# Resample data into 30min bins
bars = data.Price.resample('30min', how='ohlc')
volumes = data.Volume.resample('30min', how='sum')
This gives the error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Int64Index'
Convert the integer timestamps in the index to a DatetimeIndex:
This interprets the integers as seconds since the Epoch.
For example, given
yields
Then
can be computed: