I have the following example dataframe:
data = {'ref':['1', '2', '3', '4', '5'],
'checked':[True, True, True, False, True],
'rag':['r', 'r', 'g', 'a', 'r'],
'group':['high', 'low', 'high', 'medium', 'high']}
dataframe = pd.DataFrame(data)
I want to group on group and do some conditional counts where certain conditions are met so I get the following:
I can group by group and do n by the following:
df = dataframe.groupby(['group']).agg(
n=('ref', 'count')
).reset_index()
But I am struggling to also count the number of times for each group that:
- checked = True
- rag = g
- rag = a
- rag = r
Any help would be much appreciated!
edit: changed True/False strings to Boolean

