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
Advertisement
Answer
You should change %y into %Y, because %y is intended to be used for years written in the YY short form (like 14 for 2014), while %Y for the extended YYYY years (2014).
Try using:
df['month'] = pd.to_datetime(df['month'], format = '%Y-%m')