Skip to content

API: pass ddof down to Cythonised std / var in groupby.agg #60591

Open
@MarcoGorelli

Description

@MarcoGorelli

Say I want to do a groupby and perform various aggregations, e.g. I want to find mean and std of b. Easy:

import pandas as pd

df = pd.DataFrame({'a': [1,1,2], 'b': [4,5,6]})
df.groupby('a').agg({'b': ['mean', 'std']})

What if I want to do the same with ddof=0? If was computing a single aggregation, I could do:

print(df.groupby('a')['b'].std(ddof=0))

and that uses the Cythonized path.

However, I think the current pandas API doesn't allow a way of passing ddof to 'std' when used in .agg. The workaround often suggested in StackOverflow is (😭 ):

print(df.groupby('a').agg({'b': ['mean', lambda x: np.std(x)]}))

but that'll evade the Cythonized path, which is a missed opportunity

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions