0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
bikuser
  • 2,013
  • 4
  • 33
  • 57

1 Answers1

1

you need to convert the column to string first:

pd.to_datetime(df['date_col'].astype(str), format='%m.%Y')
khaled koubaa
  • 836
  • 3
  • 14