I have the following multiindex dataframe:
MSISDN_COUNT
NAME DIM1 SEGMENT
JAN22 N Detractor 307
Passive 198
Promoter 1256
Y Detractor 237
Passive 161
Promoter 1096
FEB22 N Detractor 313
Passive 222
Promoter 1260
Y Detractor 261
Passive 169
Promoter 1155
I want to create a new column, which will be calculated for each NAME and for each DIM1.
The calculation is:
((Promoter - Detractor) / (Promoter + Passive + Detractor) )* 100
So the expected output is
MSISDN_COUNT OUT
NAME DIM1 SEGMENT
JAN22 N Detractor 307 53.88
Passive 198
Promoter 1256
Y Detractor 237 57.49
Passive 161
Promoter 1096
FEB22 N Detractor 313 52.76
Passive 222
Promoter 1260
Y Detractor 261 56.4
Passive 169
Promoter 1155
I can't figure out how to do this with the multi-level index dataframe.
Any help is appreciated!