Skip to content

Commit b45d4b1

Browse files
committed
handle column index construction for MultiIndex
1 parent 9628816 commit b45d4b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/core/groupby/generic.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1643,8 +1643,12 @@ def _wrap_aggregated_output(
16431643
DataFrame
16441644
"""
16451645
indexed_output = {key.position: val for key, val in output.items()}
1646-
name = self._obj_with_exclusions._get_axis(1 - self.axis).name
1647-
columns = Index([key.label for key in output], name=name)
1646+
1647+
agg_axis = self._obj_with_exclusions._get_axis(1 - self.axis)
1648+
if isinstance(agg_axis, MultiIndex):
1649+
columns = Index([key.label for key in output], names=agg_axis.names)
1650+
else:
1651+
columns = Index([key.label for key in output], name=agg_axis.name)
16481652

16491653
result = self.obj._constructor(indexed_output)
16501654
result.columns = columns

0 commit comments

Comments
 (0)