pydata/pandas — pull request #4432 by guyrt (2013-08-01 18:41:53+00:00)
Title: BUG: Fixes issue #3334: brittle margin in pivot_table.

closes #3334 Brittle pivot margins

Issue was that pivot tables that use all columns of the original DataFrame in rows and cols failed on the margin computation. This is a special case for margins: one should use the index itself as the value.

>> df = DataFrame({'Response' : ['Y', 'N' ,'N', 'Y', 'Y', 'N'],
'Type' : ['A', 'A', 'B', 'B', 'B', 'C']})

>> pivot_table(df, rows='Response',cols='Type',aggfunc=len,margins=True)
>> Type A B C All
>> Response
>> N 1 1 1 3
>> Y 1 2 NaN 3
>> All 2 3 1 6