Skip to content

BUG: DataFrameGroupBy.transform with axis=1 fails #36308

Closed
@rhshadrach

Description

@rhshadrach

The following seems to happen on all transform groupby kernels:

df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df.groupby([1, 1], axis=1).transform("shift")

results in ValueError: Length mismatch: Expected axis has 2 elements, new values have 3 elements.

I think the issue is in pandas.core.groupby.generic._wrap_transformed_output; this method does not take into account self.axis when wrapping the output. All that needs to happen is result = result.T and to use the index labels rather than the column labels for columns there.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions