-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Can't use named aggregation with resample. #30092
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
xref #28380 |
take |
Tried reproducing this on master - didn't get an error, but now the two aggregations are the same:
returns
|
thanks @MarcoGorelli I think you would need to give a name for this function since those two can not be distinguished for now, so it always takes the last one to use, code below seems to work on master quant9 = partial(np.percentile, q=.9999)
quant1 = partial(np.percentile, q=.1111)
quant9.__name__ = "quant9"
quant1.__name__ = "quant1"
dfg = df.resample('3T').agg(
{'A': [quant9, quant1,]}
) assigning different names for it should work. and also i haven't had time to really work on this recently, not sure how the result will go. |
Is this something you plan on coming back to? If so, that's fine, I'll leave it to you :) If not, I might have a solution in mind which doesn't involve renaming the functions. |
awesome! pls go for it! @MarcoGorelli |
btw, i think you might need to open a new issue and address this, because this seems not related to resample, but quite general |
Hello! I posted a question on StackOverflow exactly about this issue. Could you, please, take a look? https://stackoverflow.com/questions/60788893/pandas-named-aggregation-not-working-with-resample-agg Does anyone need help with this? |
@otaviocv just got round to checking your SO post, and it seems different to this one (and indeed not fixed by the PR I have open). If you could open a new issue with it, that'd be great! |
Have opened the issue reported by @otaviocv in #34064, as it's different to this one @charlesdong1991 @jreback does this issue still need to be open? Because the original issue no longer errors, and I took the overwriting part forward here #30880 |
yeah, agree with it @MarcoGorelli ! could close this one already then to avoid duplication. |
Code Sample, a copy-pastable example if possible
Problem description
Resample, unlike groupby, has no ability to do named aggregation. This means if you use a function twice on the same column you get an error saying:
pandas.core.base.SpecificationError: Function names must be unique, found multiple named quantile
.It would be very useful to make the resample agg interface similar to the groupby agg interface. An example of the named aggregation is here: https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#named-aggregation
Expected Output
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: