I'm working with a pandas dataframe in which one column is a datetime64 object. I need to plot a bar chart of the number of rows per year, and also slice the dataframe for a month range (e.g. January 2011 to March 2011). I suppose I could add a column that captures only the year or month, but how can I do so?
I ran
df['year'], df['month'] = df['date'].dt.year, df['date'].dt.month
df
but got an AttributeError: Can only use .dt accessor with datetimelike values