Helper for column specific aggregation with control over output column names.
Subclass of typing.NamedTuple.
Column label in the DataFrame to apply aggfunc.
Function to apply to the provided column. If string, the name of a built-in pandas function.
Examples
>>> df = pd.DataFrame({"key": [1, 1, 2], "a": [-1, 0, 1], 1: [10, 11, 12]})
>>> agg_a = pd.NamedAgg(column="a", aggfunc="min")
>>> agg_1 = pd.NamedAgg(column=1, aggfunc=lambda x: np.mean(x))
>>> df.groupby("key").agg(result_a=agg_a, result_1=agg_1)
result_a result_1
key
1 -1 10.5
2 1 12.0
Attributes
| Alias for field number 1 |
| Alias for field number 0 |
Methods
| Return number of occurrences of value. |
| Return first index of value. |
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.NamedAgg.html