When using default to_datetime
, without format, the answers is sometimes a bit weird:
>>> import pandas as pd
>>> pd.to_datetime("2017-07-04 16-51-10")
Timestamp('2017-07-05 02:00:00')
Year and month are guessed correctly, day gets shifted by 1, and hour, minutes, seconds are completely off.
(edit) - Obviously the function works fine when passing the datetime format, it is the default guess that is weird.
Comment From: chris-b1
We are falling back to the dateutil parser here. It interprets the -10
as a tz offset, which I suppose makes some sense although can see why it is surprising. Closing as not pandas, xref #12585 - general dateutil compat issue.
In [20]: from dateutil.parser import parse
In [21]: parse("2017-07-04 16-51-10")
Out[21]: datetime.datetime(2017, 7, 4, 16, 0, tzinfo=tzoffset(None, -36000))