extract month from date pandas dataframe code example
Example 1: month from datetime pandas
#Exctract month and create a dedicated column df["Month"] from a
#column in datetime format df["Date"]
df['Month'] = pd.DatetimeIndex(df['Date']).month
Example 2: to extract out only year month from a date column in pandas
df['month_year'] = df['date_column'].dt.to_period('M')