我在由比特幣歷史的三列的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