| 2107 | |
| 2108 | @set_module("pandas.api.typing") |
| 2109 | class DataFrameGroupBy(GroupBy[DataFrame]): |
| 2110 | def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs): |
| 2111 | """ |
| 2112 | Aggregate using one or more operations. |
| 2113 | |
| 2114 | The ``aggregate`` function allows the application of one or more aggregation |
| 2115 | operations on groups of data within a DataFrameGroupBy object. It supports |
| 2116 | various aggregation methods, including user-defined functions and predefined |
| 2117 | functions such as 'sum', 'mean', etc. |
| 2118 | |
| 2119 | Parameters |
| 2120 | ---------- |
| 2121 | func : function, str, list, dict or None |
| 2122 | Function to use for aggregating the data. If a function, must either |
| 2123 | work when passed a DataFrame or when passed to DataFrame.apply. |
| 2124 | |
| 2125 | Accepted combinations are: |
| 2126 | |
| 2127 | - function |
| 2128 | - string function name |
| 2129 | - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` |
| 2130 | - dict of index labels -> functions, function names or list of such. |
| 2131 | - None, in which case ``**kwargs`` are used with Named Aggregation. Here the |
| 2132 | output has one column for each element in ``**kwargs``. The name of the |
| 2133 | column is keyword, whereas the value determines the aggregation used to |
| 2134 | compute the values in the column. |
| 2135 | |
| 2136 | Can also accept a Numba JIT function with |
| 2137 | ``engine='numba'`` specified. Only passing a single function is supported |
| 2138 | with this engine. |
| 2139 | |
| 2140 | If the ``'numba'`` engine is chosen, the function must be |
| 2141 | a user defined function with ``values`` and ``index`` as the |
| 2142 | first and second arguments respectively in the function signature. |
| 2143 | Each group's index will be passed to the user defined function |
| 2144 | and optionally available for use. |
| 2145 | |
| 2146 | *args |
| 2147 | Positional arguments to pass to func. |
| 2148 | engine : str, default None |
| 2149 | * ``'cython'`` : Runs the function through C-extensions from cython. |
| 2150 | * ``'numba'`` : Runs the function through JIT compiled code from numba. |
| 2151 | * ``None`` : Defaults to ``'cython'`` or globally setting |
| 2152 | ``compute.use_numba`` |
| 2153 | |
| 2154 | engine_kwargs : dict, default None |
| 2155 | * For ``'cython'`` engine, there are no accepted ``engine_kwargs`` |
| 2156 | * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil`` |
| 2157 | and ``parallel`` dictionary keys. The values must either be ``True`` or |
| 2158 | ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is |
| 2159 | ``{'nopython': True, 'nogil': False, 'parallel': False}`` and will be |
| 2160 | applied to the function |
| 2161 | |
| 2162 | **kwargs |
| 2163 | * If ``func`` is None, ``**kwargs`` are used to define the output names and |
| 2164 | aggregations via Named Aggregation. See ``func`` entry. |
| 2165 | * Otherwise, keyword arguments to be passed into func. |
| 2166 |
no outgoing calls
no test coverage detected