2015-10-01 22 views
17

我很困惑熊貓怎麼吹出界了datetime對象與這些行:大熊貓出界納秒時間戳偏移後前滾加上增加一個月偏移

import pandas as pd 
BOMoffset = pd.tseries.offsets.MonthBegin() 
# here some code sets the all_treatments dataframe and the newrowix, micolix, mocolix counters 
all_treatments.iloc[newrowix,micolix] = BOMoffset.rollforward(all_treatments.iloc[i,micolix] + pd.tseries.offsets.DateOffset(months = x)) 
all_treatments.iloc[newrowix,mocolix] = BOMoffset.rollforward(all_treatments.iloc[newrowix,micolix]+ pd.tseries.offsets.DateOffset(months = 1)) 

這裏all_treatments.iloc[i,micolix]pd.to_datetime(all_treatments['INDATUMA'], errors='coerce',format='%Y%m%d')設置日期時間,和INDATUMA是格式爲20070125的日期信息。

這個邏輯似乎是在模擬數據進行工作(沒有錯誤,日期意義),所以在那一剎那,它在我的整個數據失敗,出現以下錯誤,我不能重現:

pandas.tslib.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2262-05-01 00:00:00 
+1

[創建一個最小的,但*完整*代碼示例](http://stackoverflow.com/help/mcve) – jfs

回答

18

因爲大熊貓代表在納秒的分辨率時間戳,可以使用一個64位整數表示的時間跨度限制在約584年

pd.Timestamp.min 
Out[54]: Timestamp('1677-09-22 00:12:43.145225') 

In [55]: pd.Timestamp.max 
Out[55]: Timestamp('2262-04-11 23:47:16.854775807') 

和你的值超出該範圍2262年5月1日00:00:00,因此outofbounds錯誤

直掉:http://pandas-docs.github.io/pandas-docs-travis/timeseries.html#timestamp-limitations

+2

你知道,如果有可能有一個日期指數超越那個範圍? – mac13k

+0

@ mac13k看[this](http://pandas-docs.github.io/pandas-docs-travis/timeseries.html#timeseries-oob)... – blacksite

+0

我知道這件事,謝謝。問題是你可以讓索引由超出時間戳限制的時間範圍構成,在你真正嘗試使用該索引中的單個值的情況下,這是很好的 - 那麼你將得到錯誤或不正確的日期。 – mac13k