Skip to content

Instantly share code, notes, and snippets.

@eginez
Created August 28, 2022 18:09
Show Gist options
  • Save eginez/11e1f079e77a72faf1805ed4d10c3449 to your computer and use it in GitHub Desktop.
Save eginez/11e1f079e77a72faf1805ed4d10c3449 to your computer and use it in GitHub Desktop.
pandas group by date
# load data index on date
# time series data like credit card transactions for example
df = pd.read_csv('~/Downloads/time_series_data.csv', index_col='Date', parse_dates=True)
# group by apply data and sum
df2 = df.groupby(pd.Grouper(freq='Y')).sum()
#df2 now contains sumarized data
# show perenctiles for example
df2.quantile([0.1, 0.5, 0.8, 0.9, 0.95])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment