0
我有一個pd.DataFrame,我想每十分鐘重新採樣一次。 對於重採樣我索引我的數據幀是這樣的:Python數據幀重採樣TypeError
re_in = Re.set_index(pd.DatetimeIndex(Re['time'])) # index Re
所得有re_in看起來是這樣的:
time time T WR WS WG U R RC
2017-06-22 00:00:00 2017-06-22 00:00:00 21.8 159 5.8 7.9 66 0.0 0.0
2017-06-22 00:05:00 2017-06-22 00:05:00 21.9 173 9.0 11.9 65 0.0 0.0
2017-06-22 00:10:00 2017-06-22 00:10:00 21.9 145 4.0 4.0 66 0.0 0.0
2017-06-22 00:15:00 2017-06-22 00:15:00 21.9 158 6.8 7.9 67 0.0 0.0
2017-06-22 00:20:00 2017-06-22 00:20:00 21.9 149 6.4 7.9 68 0.0 0.0
2017-06-22 00:25:00 2017-06-22 00:25:00 21.9 156 4.7 7.9 68 0.0 0.0
2017-06-22 00:30:00 2017-06-22 00:30:00 21.8 153 3.2 4.0 69 0.0 0.0
我試圖把樣品與此代碼:
av_temp['RE_mean'] = re_in.T.resample("10T").mean() # average Re
但我收到錯誤:
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "M:/Python/Testveld/Software/selecting_date_temperature_av.py", line 234, in <module>
av_temp['WH_mean'] = re_in.T.resample(SAMPLE).mean() # average renkforce
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 4212, in resample
base=base, key=on, level=level)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\tseries\resample.py", line 944, in resample
return tg._get_resampler(obj, kind=kind)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\tseries\resample.py", line 1057, 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 'Index'
當我檢查re_in.index時,它表示它是一個DatetimeIndex。
print(re_in.index)
DatetimeIndex(['2017-06-22 00:00:00', '2017-06-22 00:05:00',
'2017-06-22 00:10:00', '2017-06-22 00:15:00',
'2017-06-22 00:20:00', '2017-06-22 00:25:00',
'2017-06-22 00:30:00', '2017-06-22 00:35:00',
'2017-06-22 00:37:00', '2017-06-22 00:42:00',
...
'2017-06-22 23:15:00', '2017-06-22 23:20:00',
'2017-06-22 23:25:00', '2017-06-22 23:30:00',
'2017-06-22 23:35:00', '2017-06-22 23:40:00',
'2017-06-22 23:45:00', '2017-06-22 23:46:00',
'2017-06-22 23:51:00', '2017-06-22 23:56:00'],
dtype='datetime64[ns]', name='time', length=288, freq=None)
我該如何解決這個問題?
你想重新採樣'T'列? – Holt