-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Allow args to be specified for the pivot_table aggfunc #57884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the request - it makes sense to me to support passing through kwargs here. The only question is how:
I do not think we should do
If we want to agree with the current direction of apply/agg/transform, it would be the first of the above three options. Ref: #40112 |
take |
Hi, regarding that first option, would passing positional arguments to the aggfunc not be supported? |
take |
Add the option of passing keyword arguments to DataFrame.pivot_table and pivot_table's aggfunc through **kwargs. Co-authored-by: Pedro Freitas <[email protected]>
@rhshadrach Sorry to bother you, but could you share your thoughts on this matter? |
@PF2100 - thanks for the ping!
Same here, but for consistency, it seems best to go with (1) for now. Changing from
Correct. |
Add the option of passing keyword arguments to DataFrame.pivot_table and pivot_table's aggfunc through **kwargs. Co-authored-by: Pedro Freitas <[email protected]>
…c keyword arguments #57884 (#58893) Co-authored-by: Pedro Freitas <[email protected]> Co-authored-by: Rui Amaral <[email protected]>
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Currently the
pivot_table
has anaggfunc
parameter which is used to do a groupby aggregation here. However, no additional arguments can be passed into thatagg
call. I'm specifically referring to the*args
which can be specified in (df/series) groupby.agg function. It would be very useful ifpivot_table
could accept additional arguments for theaggfunc
.Feature Description
I'm not 100% sure, but I think it would be something like this:
**aggfunc_args
oraggfunc_args: dict
parameter to thepivot_table
function.__internal_pivot_table
functionagged = grouped.agg(aggfunc)
toagged = grouped.agg(aggfunc, **aggfunc_args)
.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 dopd.pivot_table(... , aggfunc=sum, min_count=1)
or similiar.Additional Context
No response
The text was updated successfully, but these errors were encountered: