to extract out only year month from a date column in pandas
df['month_year'] = df['date_column'].dt.to_period('M')
to extract out only year month from a date column in pandas
df['month_year'] = df['date_column'].dt.to_period('M')
pandas extract month year from date
#if the date format comes in datetime, we can also extract the day/month/year using the to_period function
#where 'D', 'M', 'Y' are inputs
df['month_year'] = pd.to_datetime(df['birth_date']).dt.to_period('M')
df.head()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us