-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
DOC: Dict of Dicts for renaming Groupby Aggregations #9052
Comments
xref is #8593 (which would replace / enhance this) |
Thanks for the tip. Didn't realize this was possible either, this will save me from building my multicolumns "by hand". @jreback are you planning any API change for 0.16.0 on this? #8593 does not seem to interfere with this behaviour, but maybe a deeper change is planned? I'd rather not rely on this if it's not tested atm. Or would you accept a test for this? |
@Gimli510 this IS implemented. Its basically the same as the following (except the name determination is slightly different).
I haven't carefully looked thru, but I suspect their is at least 1 tests. Though would for sure accept a PR which makes these tests more prominent (e.g. test_agg_api or something).
|
from mailing list
with a trivial patch
of course need some tests...... |
acutally not closing this |
The following raises import pandas as pd
import numpy as np
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.arange(8)})
grouped = df.groupby(['A', 'B'])
grouped['D'].agg({'D': np.sum, 'result2': np.mean}) Is this intended or a bug (I'd prefer to be able to reuse the series column name)? |
This should work (it is also a regression, as it worked before). |
this is fixed in #12329
Note that this works as well, though maybe not as to the users intent (e.g. the C is exactly a label here, nothing to do with the actual aggregation columns.
|
To reference on complex groupby: and need to transform into 'groupby' : Usually, this is done by
Is there a way to this kind of complex and generic grouping in groupby pandas ? |
I didn't realize this was possible, and didn't see it in the docs.
The text was updated successfully, but these errors were encountered: