Pandas Multiindex Series Processing

Clash Royale CLAN TAG#URR8PPPPandas Multiindex Series Processing
I have a pandas 2 index serie that I got from a .groupby() on my original DataFrame:
label ncsc
False 0 297
1 537
2 333
3 207
4 51
5 12
6 4
7 2
True 0 29
1 68
2 35
3 29
4 35
5 18
6 8
7 2
Name: ncsc, dtype: int64
I would like to be able to compute for each 'ncsc' the True rate, ie, for 'ncsc'=6, True rate = 8/(4+8) = 0.66.
Do you see a way to do that with =out using a loop but with a 'pandas synthax'??
Thanks
1 Answer
1
Convert the wanted index level to a column and group by that column:
df.reset_index(level=1).groupby('ncsc').mean()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.