Skip to content

Instantly share code, notes, and snippets.

@cgddrd
Created October 24, 2018 15:12
Show Gist options
  • Save cgddrd/420878d8e2027fa7a7e8abb1f90d033e to your computer and use it in GitHub Desktop.
Save cgddrd/420878d8e2027fa7a7e8abb1f90d033e to your computer and use it in GitHub Desktop.
Pandas - Group by date and categorical column
import pandas as pd
# 'reset_index' is required to turn a multi-level index back into columns.
df.groupby([pd.Grouper(key='my_date_column', freq='1D'), 'my_categorical_column']).count().reset_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment