Home > front end >  time data '2014-01' does not match format '%y-%m'
time data '2014-01' does not match format '%y-%m'

Time:06-30

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 :

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

CodePudding user response:

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')

CodePudding user response:

%y is Year, short version, without century ,but full year should use %Y

  • Related