Skip to content

ENH: Allow args to be specified for the pivot_table aggfunc #57884

Closed
@j-kapp

Description

@j-kapp

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

Currently the pivot_table has an aggfunc parameter which is used to do a groupby aggregation here. However, no additional arguments can be passed into that agg call. I'm specifically referring to the *args which can be specified in (df/series) groupby.agg function. It would be very useful if pivot_table could accept additional arguments for the aggfunc.

Feature Description

I'm not 100% sure, but I think it would be something like this:

  1. Add a **aggfunc_args or aggfunc_args: dict parameter to the pivot_table function.
  2. Do the same for the __internal_pivot_table function
  3. Change the line here, from agged = grouped.agg(aggfunc) to agged = grouped.agg(aggfunc, **aggfunc_args).
  4. Update the docs

Alternative Solutions

The same functionality can currently be achieved by specifying a custom function as aggfunc, but using that is much slower. My use case is pretty much the same as this.
Instead of using pd.pivot_table(... , aggfunc=lambda x: x.sum(min_count=1)), I would like to be able to do pd.pivot_table(... , aggfunc=sum, min_count=1) or similiar.

Additional Context

No response

Metadata

Metadata

Assignees

Labels

EnhancementReshapingConcat, Merge/Join, Stack/Unstack, Explode

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions