Skip to content

Commit 4b5c037

Browse files
committed
modified: pandas/core/reshape/pivot.py
- Added condition to :func:`__internal_pivot_table` to aggregate `values` explicitly if `values` were passed, otherwise aggregate all remaining columns. This allows the tests :func:`test_pivot_table_values_in_columns` and :func:`test_pivot_table_values_in_index` in test_pivot_multilevel.py to pass.
1 parent 047d9e3 commit 4b5c037

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/reshape/pivot.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ def __internal_pivot_table(
336336
values = list(values)
337337

338338
grouped = data.groupby(keys, observed=observed, sort=sort, dropna=dropna)
339-
agged = grouped.agg(aggfunc, **kwargs)
339+
if values_passed:
340+
# Explicitly aggregate ``values``.
341+
agged = grouped[values].agg(aggfunc, **kwargs)
342+
else:
343+
agged = grouped.agg(aggfunc, **kwargs)
340344

341345
if dropna and isinstance(agged, ABCDataFrame) and len(agged.columns):
342346
agged = agged.dropna(how="all")

0 commit comments

Comments
 (0)