I have a dataframe similar to this:
id name status output
123 John a 33.33%
232 Wang b 50%
324 Wang a 50%
424 Cici a 100%
553 John b 33.33%
653 John b 33.33%
I need to 1) groupby name 2) count the percentage where status == a. Output is listed on the right
I used following code:
df['output'] = df.groupby('name')['id'].transform(lambda x: x[x['status == a']].count/len(x))
but the return was wrong, is there anyway I can fix this.