超出范围的纳秒级时间戳 [英] Out of bounds nanosecond timestamp
问题描述
我在Googlespeedsheet中有一个变量['date_hiring'],格式为
I have a variable ['date_hiring'] in Googlespeedsheet in format like
16.01.2016
我在Python中将其导入,该变量具有对象类型.我尝试转换为日期时间
I import it in Python, the variable has an object type. I try to convert to datetime
from datetime import datetime
data['date_hiring'] = pd.to_datetime(data['date_hiring'])
我得到
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 16-01-06 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
但是在Googlespeedsheet中的原始数据中,我没有类似"16.01.06"的数据
but in original data in the Googlespeedsheet i have no data like '16.01.06'
就像'16 .06.2006'
Just like '16.06.2006'
所以问题出在转换
如何改进它?
推荐答案
根据文档, dayfirst 字段默认为false:
According to the documentation, the dayfirst field defaults to false:
dayfirst:布尔值,默认为False
dayfirst : boolean, default False
因此,它必须确定那里有一个错误的日期,并试图将其解释为一天中的某个时间.
So it must have decided that there was a malformed date there and tried to interpret it as a time-of-day.
但是即使那样,它可能也不认为16点是几小时或几分钟,因此它尝试将其转换为秒.但是还有一个额外的小数点,所以它放弃了,说我不喜欢小数秒. (或者类似的东西.)
But even then it probably didn't think that 16 point anything could be hours or minutes, so it tried to convert it as seconds. But there is a extra decimal point so it gave up and said I don't like the fractional seconds. (Or something like that.)
我认为您可以通过提供明确的格式字符串或至少设置 dayfirst 来解决此问题.
I think you can fix it by giving an explicit format string or at least setting dayfirst.
这篇关于超出范围的纳秒级时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!