Skip to content

Instantly share code, notes, and snippets.

@justinhchae
Last active January 12, 2021 15:45
Show Gist options
  • Save justinhchae/8fd6278966f98365b2fc9c11b3e12546 to your computer and use it in GitHub Desktop.
Save justinhchae/8fd6278966f98365b2fc9c11b3e12546 to your computer and use it in GitHub Desktop.
data = {'dates':
['2012-05-04',
'2012-05-04',
'2012-06-04',
'2012-08-08'],
'types':
['a',
'a',
'z',
'z',],
'some_col':
['n',
'u',
'q',
'']
}
df['dates'] = pd.to_datetime(df['dates'])
df = df[['dates', 'types']].groupby([pd.Grouper(key='dates')]).agg('count').reset_index()
df = df.rename(columns={'types:'count'})
print(df)
"""
dates count
1 2012-06-04 1
2 2012-08-08 1
0 2012-05-04 2
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment