Skip to content

API: specification of functions in .agg #8593

Closed
@jreback

Description

@jreback

From SO

In [100]: df = pd.DataFrame({'A': ['group1', 'group1', 'group2', 'group2', 'group3', 'group3'],
                   'B': [10, 12, 10, 25, 10, 12],
                   'C': [100, 102, 100, 250, 100, 102]})

In [101]: df
Out[101]: 
        A   B    C
0  group1  10  100
1  group1  12  102
2  group2  10  100
3  group2  25  250
4  group3  10  100
5  group3  12  102

In [102]: df.groupby('A').agg(['mean',lambda x: x.iloc[1]])
Out[102]: 
           B               C          
        mean  <lambda>  mean  <lambda>
A                                     
group1  11.0        12   101       102
group2  17.5        25   175       250
group3  11.0        12   101       102

Would be nice to be able to use lambda x: x.nth(1) or maybe 'nth(1)'
In [103]: df.groupby('A').agg(['mean','nth(1')])

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapClosing CandidateMay be closeable, needs more eyeballsEnhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions