pydata/pandas — pull request #4433 by guyrt (2013-08-01 19:08:57+00:00)
Title: BUG: Fixes issue #3334: brittle margin computation in pivot_table

Adds support for margin computation when all columns are used in rows and cols.

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
This is my first PR to Pandas, so apologies for anything out of the ordinary.