Search code examples
pythonpandasdate-range

system error when creating date_range with pandas


I would like to create a date_range() with using pandas. I am kinda sure it worked before I updated pandas package.

with following line of code, I am trying to create the date_range():

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

and here is the error message:

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

What am I doing wrong?


Solution

  • Pandas version 0.19.1 date_range() does not work with the input I gave. I updated pandas to 0.23.4 now everything is fine.

    Meanwhile:

    pip3 install --upgrade pandas