超限纳秒时间戳

2024-04-20 09:22:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我在google的电子表格里有一个变量[招聘日期],格式如下

16.01.2016

我用Python导入它,变量有一个对象类型。我试图转换为日期时间

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

我从这里知道

Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years

但在谷歌电子表格的原始数据中,我没有像“16.01.06”这样的数据

就像2006年6月16日

所以问题在于

如何改进?


Tags: to对象fromimport类型datadatetimedate
1条回答
网友
1楼 · 发布于 2024-04-20 09:22:30

根据documentation,dayfirst字段默认为false:

dayfirst : boolean, default False

所以它一定是认定那里有一个不正常的日期,并试图将其解释为一天中的一个时间。

但即便如此,它可能也不认为16分可以是几小时或几分钟,所以它试图将其转换为几秒。但是有一个额外的小数点,所以它放弃了,说我不喜欢小数秒。(或者类似的东西。)

我认为您可以通过提供显式格式字符串或至少设置dayfirst来修复它。

相关问题 更多 >