Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
DOC: Dict of Dicts for renaming Groupby Aggregations #9052
Comments
TomAugspurger
added Groupby API Design
labels
Dec 10, 2014
TomAugspurger
added this to the
0.16.0
milestone
Dec 10, 2014
|
xref is #8593 (which would replace / enhance this) |
Gimli510
commented
Dec 11, 2014
|
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).
|
jreback
referenced
this issue
Mar 4, 2015
Open
ENH: groupby aggregate with multi-level columns #9585
jreback
modified the milestone: 0.16.0, Next Major Release
Mar 6, 2015
|
from mailing list
with a trivial patch
of course need some tests...... |
jreback
added Difficulty Novice Effort Low Prio-medium
labels
Nov 12, 2015
jreback
referenced
this issue
Nov 21, 2015
Merged
API: provide Rolling/Expanding/EWM objects for deferred rolling type calculations #10702 #11603
|
I do not really like this:
The fact that Also, it is a bit strange that it works on
So apparantly |
|
I think the most important is to have a clear set of rules how the (nested) dicts are interpreted. Eg:
The above are the current rules (as far as I know from using it, I don't know if everything is explicitly meant/tested/documented to be the rules).
But allowing to let the first level of the dict to be the custom names instead of column names (as implemented in #11603) to ease this case:
seems like a potential rabbit hole to me .. (possible conflicts between existing column names / custom names, behaviour dependent on the presence of a column with a certain name, ..) So I would rather vote to keep the rules as above, and remove the distinction between |
jreback
added a commit
to jreback/pandas
that referenced
this issue
Dec 19, 2015
|
|
jreback |
36fb835
|
jreback
closed this
in #11603
Dec 19, 2015
|
acutally not closing this |
jreback
reopened this
Dec 19, 2015
jreback
added a commit
to jreback/pandas
that referenced
this issue
Feb 2, 2016
|
|
jreback |
e243f18
|
jreback
closed this
in 1dc49f5
Feb 2, 2016
|
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). |
jorisvandenbossche
reopened this
Feb 14, 2016
jorisvandenbossche
modified the milestone: 0.18.0, Next Major Release
Feb 14, 2016
jreback
added a commit
to jreback/pandas
that referenced
this issue
Feb 15, 2016
|
|
jreback |
66c23aa
|
jreback
referenced
this issue
Feb 15, 2016
Closed
BUG: addtl fix for compat summary of groupby/resample with dicts #12329
|
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.
|
jreback
closed this
in cac5f8b
Feb 15, 2016
This was referenced Oct 14, 2016
arita37
commented
Jan 28, 2017
|
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 ? |
TomAugspurger commentedDec 10, 2014
I didn't realize this was possible, and didn't see it in the docs.