I have a dataframe which looks like this -
group outcome_30 outcome_365
307 control no event no event
141 treatment no event no event
291 control no event no event
138 treatment no event no event
320 control no event no event
189 treatment no event no event
16 treatment stroke stroke
227 control stroke stroke
10 treatment stroke stroke
257 control no event no event
I tried to create a pivot table using this code -
stent_pt = stent.pivot_table(index='group', values=['outcome_30','outcome_365'], aggfunc='count')
stent_pt
outcome_30 outcome_365
group
control 227 227
treatment 224 224
But this is not what I am looking for. I want to do the count by (no event, stroke) for the outcome30 and also for the outcome365.
This is how I want my result to look like -