![](/img/trans.png)
[英]pandas Sqlite and resample error Only valid with DatetimeIndex
[英]Resample to DatetimeIndex raises an error
我創建了一個DatetimeIndex,我想用該索引重新采樣數據。 當我這樣做時,我得到一個例外:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-i686.egg/pandas/core/generic.py", line 188, in resample
limit=limit, base=base)
File "/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-i686.egg/pandas/tseries/resample.py", line 41, in __init__
self.freq = to_offset(freq)
File "/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-i686.egg/pandas/tseries/frequencies.py", line 392, in to_offset
raise ValueError("Could not evaluate %s" % freqstr)
ValueError: Could not evaluate <class 'pandas.tseries.index.DatetimeIndex'>
[2012-03-02 09:00:00, ..., 2012-03-02 15:00:00]
Length: 73, Freq: 5T, Timezone: None
似乎應該使用TimeGrouper.resample處理DatetimeIndex,但在TimeGrouper初始化中對to_offset的調用卻不能。 但是我可能在這里錯過了一些東西。
知道如何通過索引重新采樣嗎? 也許是一種解決方法-我想要做的只是以某個頻率(例如1Min)進行采樣,但是開始/結束時間不一定在原始時間序列中具有數據點(我正在嘗試一堆時間序列是從上午8點到下午4點進行采樣,但有些時間值僅是上午9:30,某些值是10am等)
抱歉,您無法傳遞DatetimeIndex進行重采樣。 解決方法是,僅按頻率別名('1Min')重新采樣,然后重新索引到生成的索引?
我開始了一個github問題 ,也許想考慮添加其他參數以進行重采樣。 隨時在此留下更多反饋。
前幾天,我發布了一個類似的問題: 熊貓的日期范圍
韋斯回答說他計划最終擴大像這樣的resample
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.