pydata/pandas — pull request #4358 by guyrt (2013-07-25 14:19:36+00:00)
Title: Fix brittle pivot margins

Addresses issue #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

This is my first PR to Pandas, so apologies for anything out of the ordinary.