Issue
I have a date column in my dataframe that I want to use at an index in that dataframe. I tried to convert this columns using pd.to_datetime()
but it did not work.
My columns containing date looks like:
0 9.2017
1 10.2017
2 11.2017
3 12.2017
4 1.2018
Error that I am getting is:
ValueError: time data '9' does not match format '%m.%YYYY' (match)
Is that related with formatting or I need to use some other library?
Solution
you need to convert the column to string first:
pd.to_datetime(df['date_col'].astype(str), format='%m.%Y')
Answered By - khaled koubaa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.