我在由比特币历史的三列的CSV文件,如下所示:为什么这个python-panda操作返回一个错误?
1500326826,2174.000000000000,0.027612680000
1500326826,2174.000000000000,0.158374090000
1500326826,2174.000000000000,0.100000000000
1500326834,2174.000000000000,2.000000000000
...
我试图让10分钟这样的时间间隔的OHLC:
data_frame=
pd.read_csv('./btcmag/raw_initial_currency_data/krakenUSD.csv',
names=['Date_Time', 'Price', 'Volume'], index_col=0, parse_dates=True)
data_price = data_frame['Price'].resample('10Min').ohlc()
我尝试不同的方法,对于〔实施例:
data_price = data_frame.resample('10Min').ohlc()
但总是在命令行中得到这样的:
data_price = data_frame['Price'].resample('10Min').ohlc()
File "/Users/john/.virtualenvs/btcmag/lib/python2.7/site-packages/pandas/core/generic.py", line 4729, in resample
base=base, key=on, level=level)
File "/Users/john/.virtualenvs/btcmag/lib/python2.7/site-packages/pandas/core/resample.py", line 969, in resample
return tg._get_resampler(obj, kind=kind)
File "/Users/john/.virtualenvs/btcmag/lib/python2.7/site-packages/pandas/core/resample.py", line 1091, in _get_resampler
"but got an instance of %r" % type(ax).__name__)
TypeError:
Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex,
but got an instance of 'Int64Index'
我是这个总的新手,甚至没有通过文档阅读,我可以找出什么是错的。
设定前data_price试'data_frame [ “DATE_TIME”] = data_frame.to_datetime(data_frame [ “DATE_TIME”],单位= “S”'。我猜测熊猫不实现10位整数是秒的感觉时代,所以你需要先用'unit ='s''来转换它 – Tony