大 pandas 超出边界毫秒时间戳后偏移前滚加上一个月的偏移 [英] pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset
问题描述
我很困惑,大熊猫如何从datetime对象中排除这些行:
I am confused how pandas blew out of bounds for datetime objects with these lines:
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
的日期信息。
Here all_treatments.iloc[i,micolix]
is a datetime set by pd.to_datetime(all_treatments['INDATUMA'], errors='coerce',format='%Y%m%d')
, and INDATUMA
is date information in the format 20070125
.
这个逻辑似乎适用于模拟数据(没有错误,日期有意义),所以当我无法再现时,它失败在我的整个数据中出现以下错误:
This logic seems to work on mock data (no errors, dates make sense), so at the moment I cannot reproduce while it fails in my entire data with the following error:
pandas.tslib.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2262-05-01 00:00:00
推荐答案
由于熊猫代表时间戳,以纳秒为单位分辨率,可以使用64位整数表示的时间限制限制在大约584年
Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years
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-05-01 00:00:00,因此outofbounds错误
And your value is out of this range 2262-05-01 00:00:00 and hence the outofbounds error
直接出来: http://pandas-docs.github.io/pandas-docs-travis/timeseries.html#timestamp-limitations
这篇关于大 pandas 超出边界毫秒时间戳后偏移前滚加上一个月的偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!