From df85cdd3c186b0cdb27876d34e69277b133a9d65 Mon Sep 17 00:00:00 2001 From: Alex-Gregory-1 <49785867+Alex-Gregory-1@users.noreply.github.com> Date: Thu, 22 Jul 2021 22:50:02 +0100 Subject: [PATCH] TST: Added test for issue 26568 (#42591) --- pandas/tests/reshape/test_pivot.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 97e933e9821af1..528d4d29b5bb77 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2148,6 +2148,23 @@ 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):