1

I have such a time data column in a pandas dataframe df:

'31/03/21 00'

00 is the hour of a day.

I now want to get thie data to datetime-format and used this code:

df['time'] = pd.to_datetime(df['time'], format = 'dd/mm/YY HH')

But get this error:

ValueError: time data '31/03/21 00' does not match format 'dd/mm/YY HH' (match)

I am now wondering how to modify the format option in order to get what I want?

Tobitor
  • 1,388
  • 1
  • 23
  • 58

1 Answers1

1

You can check https://strftime.org/ for formats:

df = pd.DataFrame({'time' : ['31/03/21 00', '05/03/21 00']})

df['time'] = pd.to_datetime(df['time'], format = '%d/%m/%y %H')

print (df)
        time
0 2021-03-31
1 2021-03-05
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252