pandas 越界纳秒时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39905822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:09:41  来源:igfitidea点击:

Out of bounds nanosecond timestamp

pythondatetimepandas

提问by Edward

I have a variable ['date_hiring'] in Googlespeedsheet in format like

我在 Googlespeedsheet 中有一个变量 ['date_hiring'] 格式如下

16.01.2016

I import it in Python, the variable has an object type. I try to convert to datetime

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

from datetime import datetime
data['date_hiring'] = pd.to_datetime(data['date_hiring'])

and i get

我明白了

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 16-01-06 00:00:00

i know from this pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offsetthat

我从这个知道Pandas界纳秒时间戳的出偏移前滚加上增加一个月偏移后

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

由于 pandas 以纳秒分辨率表示时间戳,因此可以使用 64 位整数表示的时间跨度被限制为大约 584 年

but in original data in the Googlespeedsheet i have no data like '16.01.06'

但在 Googlespeedsheet 的原始数据中,我没有像“16.01.06”这样的数据

Just like '16.06.2006'

就像'16.06.2006'

So the problem is in converting

所以问题在于转换

How to improve it?

如何改进它?

采纳答案by wallyk

According to the documentation, the dayfirstfield defaults to false:

根据文档dayfirst字段默认为 false:

dayfirst : boolean, default False

dayfirst : 布尔值,默认为 False

So it must have decided that there was a malformed date there and tried to interpret it as a time-of-day.

所以它一定已经确定那里有一个格式错误的日期并试图将它解释为一天中的时间。

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.)

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

I think you can fix it by giving an explicit format string or at least setting dayfirst.

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