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

Issue when parsing string date from CSV in Jupyter notebook

I am trying to parse a string date from a CSV in a Jupyter notebook:

from datetime import datetime
print(datetime.strptime('Aug 28, 2022', 'MMM d, yyyy'))

but I get the following error:

ValueError: time data 'Aug 28, 2022' does not match format 'MMM d, yyyy'

What am I doing 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 :

Use other format string (format codes reference):

from datetime import datetime

print(datetime.strptime("Aug 28, 2022", "%b %d, %Y"))

Prints:

2022-08-28 00:00:00
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