Last active
January 12, 2021 15:45
-
-
Save justinhchae/8fd6278966f98365b2fc9c11b3e12546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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