Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created February 21, 2018 09:38
Show Gist options
  • Save yassineAlouini/87b9178c4a09e97acf2e94ee0c8606b0 to your computer and use it in GitHub Desktop.
Save yassineAlouini/87b9178c4a09e97acf2e94ee0c8606b0 to your computer and use it in GitHub Desktop.
Histogram computation on a multi-index
import pandas as pd
df = pd.DataFrame({'t': [1, 2, 3, 4, 5, 6], 'sid': [1, 1, 1, 2, 2, 2], 'time': [1, 2, 2, 2, 1, 1]})
hist_df = df.groupby(['sid', 'time']).t.value_counts(bins=[1, 2, 3, 10]).reset_index(name='counts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment