1df['date'] = pd.to_datetime(df['date'],format='%Y%m%d')
2df['year'] = pd.DatetimeIndex(df['date']).year
3df['month'] = pd.DatetimeIndex(df['date']).month
1#Exctract month and create a dedicated column df["Month"] from a
2#column in datetime format df["Date"]
3df['Month'] = pd.DatetimeIndex(df['Date']).month
4
5
1#if the date format comes in datetime, we can also extract the day/month/year using the to_period function
2#where 'D', 'M', 'Y' are inputs
3df['month_year'] = pd.to_datetime(df['birth_date']).dt.to_period('M')
4df.head()
5