Skip to content

Commit 39904e2

Browse files
committed
handle column index construction for MultiIndex
1 parent 9787744 commit 39904e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/core/groupby/generic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,12 @@ def _wrap_aggregated_output(
16451645
DataFrame
16461646
"""
16471647
indexed_output = {key.position: val for key, val in output.items()}
1648-
name = self._obj_with_exclusions._get_axis(1 - self.axis).name
1649-
columns = Index([key.label for key in output], name=name)
1648+
1649+
agg_axis = self._obj_with_exclusions._get_axis(1 - self.axis)
1650+
if isinstance(agg_axis, MultiIndex):
1651+
columns = Index([key.label for key in output], names=agg_axis.names)
1652+
else:
1653+
columns = Index([key.label for key in output], name=agg_axis.name)
16501654

16511655
result = self.obj._constructor(indexed_output)
16521656
result.columns = columns

0 commit comments

Comments
 (0)