在resample
DataFrame上使用panda 函数以将tick数据转换为OHLCV时,会遇到重采样错误.
我们该如何解决错误?
data = pd.read_csv('tickdata.csv', header=None, names=['Timestamp','Price','Volume']).set_index('Timestamp')
data.head()
Run Code Online (Sandbox Code Playgroud)
# Resample data into 30min bins
ticks = data.ix[:, ['Price', 'Volume']]
bars = ticks.Price.resample('30min', how='ohlc')
volumes = ticks.Volume.resample('30min', how='sum')
Run Code Online (Sandbox Code Playgroud)
这给出了错误:
TypeError: Only valid with DatetimeIndex or PeriodIndex
Run Code Online (Sandbox Code Playgroud)