diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 97e933e9821af..2abf536f5a6e0 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2148,6 +2148,38 @@ def test_pivot_table_sort_false(self): ) tm.assert_frame_equal(result, expected) + def test_pivot_table_with_margins_and_numeric_columns(self): + # GH 26568 + + df = DataFrame([ + ['a', 'x', 1], + ['a', 'y', 2], + ['b', 'y', 3], + ['b', 'z', 4] + ]) + df.columns = [10, 20, 30] + + result = df.pivot_table( + index=10, + columns=20, + values=30, + aggfunc="sum", + fill_value=0, + margins=True + ) + + expected = DataFrame([ + [1, 2, 0, 3], + [0, 3, 4, 7], + [1, 5, 4, 10] + ]) + expected.columns = ['x', 'y', 'z', 'All'] + expected.index = ['a', 'b', 'All'] + expected.columns.name = 20 + expected.index.name = 10 + + tm.assert_frame_equal(result, expected) + class TestPivot: def test_pivot(self):