gpt4 book ai didi

pandas - 为什么我得到 'Cannot infer dst time from ' 2017-10-29 02 :04:1 5', try using the ' ambiguous' argument?

转载 作者:行者123 更新时间:2023-12-02 00:49:40 25 4
gpt4 key购买 nike

我设法创建了一个显示相同行为的最小示例:

>>> import pandas as pd
>>> df = pd.DataFrame({'id': [1], 'date': ['2017-10-29 02:04:15']})
>>> df['date'] = pd.to_datetime(df['date'])
>>> df['date'].dt.tz_localize('Europe/Berlin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/accessor.py", line 88, in f
return self._delegate_method(name, *args, **kwargs)
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/indexes/accessors.py", line 99, in _delegate_method
result = method(*args, **kwargs)
File "/home/math/.local/lib/python3.5/site-packages/pandas/core/indexes/datetimes.py", line 2368, in tz_localize
errors=errors)
File "pandas/_libs/tslibs/conversion.pyx", line 977, in pandas._libs.tslibs.conversion.tz_localize_to_utc
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from '2017-10-29 02:04:15', try using the 'ambiguous' argument

为什么会出现这个错误?

documentation of tz_localize没有正确解释这一点。

最佳答案

错误消息表明它无法推断夏令时。现在,可能大家都知道,从夏令时到正常时间的更改发生在 10 月底的凌晨 2:00/3:00,事实上,快速浏览一下日历就知道 2017 年的夏令时更改已经开始10 月 29 日

从夏令时到正常时间的更改是这样发生的:

  1. 时钟按照夏令时运行,时间为凌晨 2:00 至 2:59:59.99999999…am
  2. 在凌晨 3:00 整,时钟再次跳至凌晨 2:00,现在是正常时间。

因此,时钟显示两个不同的时间2017-10-29 02:04:15。或者,换句话说,在不知道您是否在谈论 DST 的情况下,时间 2017-10-29 02:04:15 是不明确的……这正是错误所说的。

关于pandas - 为什么我得到 'Cannot infer dst time from ' 2017-10-29 02 :04:1 5', try using the ' ambiguous' argument?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51872791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com