Skip to content

Allow Keyword Aggregation in DataFrame.agg and Series.agg #26513

Closed
@TomAugspurger

Description

@TomAugspurger

Followup to #26399

In [2]: df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})

In [3]: df
Out[3]:
   A  B
0  1  1
1  2  2
2  1  3
3  2  4

In [4]: df.agg(foo=("B", "sum"))

Expected Output

In [13]: df.agg({"B": {"foo": "sum"}})
/Users/taugspurger/Envs/dask-dev/lib/python3.7/site-packages/pandas/core/frame.py:6284: FutureWarning: using a dict with renaming is deprecated and will be removed in a future version
  result, how = self._aggregate(func, axis=axis, *args, **kwargs)
Out[13]:
      B
foo  10

without the warning. Similar for Series.agg

In [16]: df.B.agg({"foo": "sum"})  # allow foo="sum"
Out[16]:
foo    10
Name: B, dtype: int64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions