Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

time data does not match format (match)

I got the following error:

time data '23-MAY-2019 12:49:08' does not match format '%d-%m-%yyyy %H:%M:%S' (match)

this is my code:

dfbaseline['Date'] = pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')

What’s wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are two problems with your date format.

pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')
                                              ^^^^^^^^
  • %m is used to match Month in a zero-padded decimal number
    format
    (01 to 12).
  • %y will match year without century as a zero-padded decimal number(00, 01, …, 99)

So you have to change,

  • %b to match Month in a locale’s abbreviated name(Jan/Feb/Mar etc)
  • %Y to match Year with century as a decimal number(0001, 0002, …, 2013, 2014, …, 9998, 9999)
pd.to_datetime(dfbaseline['Date'], format='%d-%b-%Y %H:%M:%S')
                                              ^^^^^

See strftime() and strptime() Format Codes for more information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading