@@ -781,10 +781,19 @@ def test_pivot_table_with_iterator_values(self):
781
781
782
782
def test_pivot_table_margins_name_with_aggfunc_list (self ):
783
783
# GH 13354
784
- margins_name = 'Weekly'
785
- table = self .data .pivot_table (index = 'A' , columns = 'B' , margins = True ,
786
- margins_name = margins_name , aggfunc = [np .mean , max ])
787
- self .assertEqual (table [:][:].index [2 ], margins_name )
784
+ margins_name = 'Weekly'
785
+ costs = pd .DataFrame ({'item' :['bacon' ,'cheese' ,'bacon' ,'cheese' ],
786
+ 'cost' :[2.5 ,4.5 ,3.2 ,3.3 ],
787
+ 'day' :['M' ,'M' ,'T' ,'T' ]})
788
+ table = costs .pivot_table (index = "item" ,columns = "day" ,margins = True ,
789
+ margins_name = margins_name ,aggfunc = [np .mean ,max ])
790
+ ix = pd .Index (['bacon' , 'cheese' , margins_name ], dtype = 'object' , name = 'item' )
791
+ tups = [('mean' , 'cost' , 'M' ), ('mean' , 'cost' , 'T' ),
792
+ ('mean' , 'cost' , margins_name ), ('max' , 'cost' , 'M' ),
793
+ ('max' , 'cost' , 'T' ), ('max' , 'cost' , margins_name )]
794
+ cols = pd .MultiIndex .from_tuples (tups , names = [None , None , 'day' ])
795
+ expected = pd .DataFrame (table .values , index = ix , columns = cols )
796
+ tm .assert_frame_equal (table , expected )
788
797
789
798
790
799
class TestCrosstab (tm .TestCase ):
0 commit comments