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#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