I have month column with values formatted as: 2019M01 To find the seasonality I need this formatted into Pandas DateTime format. How to format 2019M01 into datetime so that I can use it for my seasonality plotting? Thanks.
Advertisement
Answer
Use to_datetime
with format
parameter:
JavaScript
x
13
13
1
print (df)
2
date
3
0 2019M01
4
1 2019M03
5
2 2019M04
6
7
df['date'] = pd.to_datetime(df['date'], format='%YM%m')
8
print (df)
9
date
10
0 2019-01-01
11
1 2019-03-01
12
2 2019-04-01
13