To group by multiple criteria, pass a list of columns or criteria:
df['birthdate'].groupby([df.birthdate.dt.year, df.birthdate.dt.month]).agg('count')
Example:
In [165]: df = pd.DataFrame({'birthdate':pd.date_range(start=dt.datetime(2015,12,20),end=dt.datetime(2016,3,1))}) df.groupby([df['birthdate'].dt.year, df['birthdate'].dt.month]).agg({'count'}) Out[165]: birthdate count birthdate birthdate 2015 12 12 2016 1 31 2 29 3 1
UPDATE
Starting with version 0.23.0 , the above code no longer works due to the restriction that the names of 0.23.0 levels must be unique, now you need rename levels for this to work:
In[107]: df.groupby([df['birthdate'].dt.year.rename('year'), df['birthdate'].dt.month.rename('month')]).agg({'count'}) Out[107]: birthdate count year month 2015 12 12 2016 1 31 2 29 3 1
source share