We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9787744 commit 39904e2Copy full SHA for 39904e2
pandas/core/groupby/generic.py
@@ -1645,8 +1645,12 @@ def _wrap_aggregated_output(
1645
DataFrame
1646
"""
1647
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)
+
+ 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)
1654
1655
result = self.obj._constructor(indexed_output)
1656
result.columns = columns
0 commit comments