相关疑难解决方法(0)

Pandas重采样错误:仅对DatetimeIndex或PeriodIndex有效

resampleDataFrame上使用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)

python pandas

29
推荐指数
1
解决办法
5万
查看次数

标签 统计

pandas ×1

python ×1