Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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()
Source by www.interviewqs.com #
 
PREVIOUS NEXT
Tagged: #pandas #extract #month #year #date
ADD COMMENT
Topic
Name
2+9 =