0

My dataframe have one column date which has the following data:

0         2019/5/20 22:49:29
1         2019/5/20 23:18:23
2           2019/3/8 9:11:35
3           2019/3/8 9:19:58
4         2019/5/20 22:57:12
5           2019/3/8 9:06:41

How can I convert it to format year-month:

0         2019-05
1         2019-05
2         2019-03
3         2019-03
4         2019-05
5         2019-03

Thank you.

ah bon
  • 9,293
  • 12
  • 65
  • 148

1 Answers1

1

It works:

df['date'] = pd.to_datetime(df['date']).dt.to_period('M')
ah bon
  • 9,293
  • 12
  • 65
  • 148