@@ -556,9 +556,11 @@ def _normalize(table, normalize, margins, margins_name='All'):
556
556
table = table .fillna (0 )
557
557
558
558
elif margins is True :
559
-
560
559
column_margin = table .loc [:, margins_name ].drop (margins_name )
561
- index_margin = table .loc [margins_name , :].drop (margins_name )
560
+ if isinstance (table .index , MultiIndex ):
561
+ index_margin = table .loc [margins_name , :].iloc [0 ].drop (margins_name )
562
+ else :
563
+ index_margin = table .loc [margins_name , :].drop (margins_name )
562
564
table = table .drop (margins_name , axis = 1 ).drop (margins_name )
563
565
# to keep index and columns names
564
566
table_index_names = table .index .names
@@ -582,8 +584,11 @@ def _normalize(table, normalize, margins, margins_name='All'):
582
584
column_margin = column_margin / column_margin .sum ()
583
585
index_margin = index_margin / index_margin .sum ()
584
586
index_margin .loc [margins_name ] = 1
585
- table = concat ([table , column_margin ], axis = 1 )
586
- table = table .append (index_margin )
587
+ table [margins_name ] = column_margin
588
+ if isinstance (table .index , MultiIndex ):
589
+ table .loc [(margins_name , '' ), :] = index_margin
590
+ else :
591
+ table .loc [margins_name ] = index_margin
587
592
588
593
table = table .fillna (0 )
589
594
0 commit comments