用熊猫创建date_range时发生系统错误

时间:2018-11-13 15:14:17

标签: python pandas date-range

我想使用熊猫创建一个date_range()。我确定在更新熊猫软件包之前可以使用。

使用以下代码行,我正在尝试创建date_range()

date_time_index = pd.date_range(start='1/1/2018', periods=8760, freq='H')

,这是错误消息:

ValueError: Error parsing datetime string "1/1/2018" at position 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 36, in <module>
    date_time_index = pd.date_range(start='1/1/2018', periods=8760, freq='H')
  File "/usr/local/lib/python3.6/dist-packages/pandas/tseries/index.py", line 2024, in date_range
    closed=closed, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pandas/util/decorators.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pandas/tseries/index.py", line 301, in __new__
    ambiguous=ambiguous)
  File "/usr/local/lib/python3.6/dist-packages/pandas/tseries/index.py", line 403, in _generate
    start = Timestamp(start)
  File "pandas/tslib.pyx", line 406, in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:9940)
  File "pandas/tslib.pyx", line 1401, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:25239)
  File "pandas/tslib.pyx", line 1516, in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26859)
  File "pandas/src/datetime.pxd", line 141, in datetime._string_t
SystemError: <class 'str'> returned a result with an error set

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

Pandas版本0.19.1 date_range()不适用于我提供的输入。我将熊猫更新为0.23.4,现在一切正常。

同时:

pip3 install --upgrade pandas