Skip to content

Commit 17f6cbb

Browse files
authored
TST: Added test for issue 26568 (#42591)
1 parent cc4eb45 commit 17f6cbb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/reshape/test_pivot.py

+17
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,23 @@ def test_pivot_table_sort_false(self):
21482148
)
21492149
tm.assert_frame_equal(result, expected)
21502150

2151+
def test_pivot_table_with_margins_and_numeric_columns(self):
2152+
# GH 26568
2153+
df = DataFrame([["a", "x", 1], ["a", "y", 2], ["b", "y", 3], ["b", "z", 4]])
2154+
df.columns = [10, 20, 30]
2155+
2156+
result = df.pivot_table(
2157+
index=10, columns=20, values=30, aggfunc="sum", fill_value=0, margins=True
2158+
)
2159+
2160+
expected = DataFrame([[1, 2, 0, 3], [0, 3, 4, 7], [1, 5, 4, 10]])
2161+
expected.columns = ["x", "y", "z", "All"]
2162+
expected.index = ["a", "b", "All"]
2163+
expected.columns.name = 20
2164+
expected.index.name = 10
2165+
2166+
tm.assert_frame_equal(result, expected)
2167+
21512168

21522169
class TestPivot:
21532170
def test_pivot(self):

0 commit comments

Comments
 (0)