Last active
January 12, 2021 15:11
-
-
Save justinhchae/5c14f7bd21b26a0993f9e5c2a19e27cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| gitcsv = 'https://raw.githubusercontent.com/justinhchae/medium/main/sample.csv' | |
| df = pd.read_csv(gitcsv, index_col=0) | |
| df['dates'] = pd.to_datetime(df['dates']) | |
| freq='M' | |
| df = df.groupby(['types', pd.Grouper(key='dates', freq=freq)])['types'].agg(['count']).reset_index() | |
| print(df) | |
| """ | |
| types dates count | |
| 0 b 2016-01-31 1 | |
| 1 a 2016-01-31 5 | |
| 2 b 2016-02-29 3 | |
| 3 a 2016-02-29 4 | |
| 4 b 2016-03-31 3 | |
| 5 a 2016-03-31 6 | |
| 6 b 2016-04-30 1 | |
| ... | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment