I have the following dataframe:
d = {'ID':['X1','Y1','Z3','X1','X1','Z3','L1','H5','H5','H5'],'Prob':[0,0,1,1,1,1,0,0,0,0]}
frame = pd.DataFrame(d)
I am trying to count the number of times a 0 or 1 occurs within the prob column and then create new columns indicating the individual count:
ID zero_count one_count
X1 1 2
Y1 1 0
Z3 0 2
L1 1 0
H5 3 0
I have tried the following but not managed it so far:
frame.groupby(['ID','prob'])['index'].count().reset_index(name='zero_count')
Any ideas would be great.