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 '2014-01' does not match format '%y-%m'

im new to this python, and i want to convert month column from object to date in jupyter notebook using python.

Here is my dataframe :

Month   Fee
2014-01 350800
2014-02 113800
2014-03 375200
2014-04 142200
2014-05 304500

and the code is :

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

df['month'] = pd.to_datetime(df['month'], format = '%y-%m')

can anyone explain what is wrong with my code? cause i think the format was correct with year and month

>Solution :

the solution is change your %y to %Y, because %y is use for short year like ’14’ and %Y is use for year like you use ‘2014’.

so change it like this :

df['month'] = pd.to_datetime(df['month'], format = '%Y-%m')
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