【发布时间】:2020-06-19 07:57:26
【问题描述】:
我很困惑 pandas 是如何用这些行超出日期时间对象的范围的:
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
【问题讨论】:
标签: python datetime pandas datetimeoffset