Skip to content

ENH: GroupBy.transform should accept similar arguments to GroupBy.agg #58318

Open
@WillAyd

Description

@WillAyd

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

In [8]: df = pd.DataFrame({"col": list("aab"), "val": range(3)})
In [8]: df.groupby("col").agg(["sum", "min"])
Out[8]: 
    val    
    sum min
col        
a     1   0
b     2   2
In [9]: df.groupby("col").transform(["sum", "min"])
TypeError: 'list' object is not callable

Feature Description

To get people out of the mindset of always using apply, it would be nice if .transform supported the same call signature as .agg

Additionally it would be great to support NamedAgg somehow in transform. The naming is a bit unfortunate...we could create a NamedTransform alias or maybe just live with the API inconsistency of:

.agg(col_a=NamedAgg("col", "sum"), ...)
.transform(col_a=NamedAgg("col", "cumsum"), ...)

I think either is still a net improvement over today

Alternative Solutions

n/a

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions