I have a dataframe df
, where I want to set the column 'Time' to a datetimeindex. The column before converting looks like this:
01-10-19 09:05
01-10-19 10:04
01-10-19 11:05
01-10-19 12:04
01-10-19 13:04
...
31-05-20 22:05
31-05-20 23:05
01-06-20 00:05
01-06-20 01:05
01-06-20 02:05
So I tried the following line of code:
df['Time'] = pd.to_datetime(df['Time'], format='%d-%m-%Y %H:%M', errors='coerce')
Which lead to only NaT 'values' in the column, without datetimeindex being installed. I've also tried to change the format in multiple ways such as: '%%dd-%%mm-%%YY %%HH:%%MM'
or '%d%d-%m%m-%Y%Y %H%H:%M%M'
, but it resulted in the same error.
When I remove the errors='coerce'
, I got the message: ValueError: time data '09:05' does not match format '%d-%m-%Y %H:%M' (match)
. What am I missing? Why is it the wrong format and how do I fix it? Thanks very much in advance!