We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9628816 commit b45d4b1Copy full SHA for b45d4b1
pandas/core/groupby/generic.py
@@ -1643,8 +1643,12 @@ def _wrap_aggregated_output(
1643
DataFrame
1644
"""
1645
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)
+
+ 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)
1652
1653
result = self.obj._constructor(indexed_output)
1654
result.columns = columns
0 commit comments