-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: groupby.agg with more than one lambda is not allowed? #7186
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
You can specify a dictionary; this requires named columns. I suppose it could work, not 100% sure why it was done this way (it needs unique functions as the results are returned as a dictionary; they could in theory be returned as a list I think that could simply create columns).
|
Thanks! |
going to close this; if you fee that this really should be implemented, pls reopen (and if you can submit a PR!) |
The proposed workaround throws a FutureWarning in the current version of pandas. Should this bug be reopened? |
That's indeed an unfortunate side effect of the deprecation.
Something else we have been discussing is to allow kwargs to be different functions, something like:
but this has not been implemented (and has some additional difficulties, as how to deal with kwargs that could be passed to the function) |
|
This has caused me huge frustration and I believe this should be updated to allow passing the same function and then providing the desired name of the output column. I'm working with a custom aggregation function that takes an additional argument by using functool's partial or simply using multiple lambda functions. I was hoping to avoid 6 separate named functions, but with the current method I have to do that, even though each function is only slightly different than the other. The "workarounds" here don't save any time compared to just having separately defined functions that are all very similar. |
I have found a more satisfactory workaround, specifically for the case where you want to apply multiple similar functions to the same column. You can create a function factory like so:
Here I'm checking how many records per day have a certain IP. Basically you can alter the name of the function returned manually and avoid the Specification Error. |
I am doing something like this and I run into similar error
Here is the error I get I think it should be allowed to do something like this. In practical scenarios people could be generating multiple lambda functions to apply. |
I'm experiencing the same problem |
Same problem here. Push. |
consider the following example
I have grouped the values in
a
byb
.Now, if I want to plot the trend over the groups with mean and std I can do
which gives me
while
which has just one lambda works ok.
Is this a bug?
In order to make the thing work I had to define real functions (i.e. in terms of
def
), to be put inagg
.The text was updated successfully, but these errors were encountered: