SeriesGroupBy.
aggregate
Aggregate using one or more operations over the specified axis.
Function to use for aggregating the data. If a function, must either work when passed a Series or when passed to Series.apply.
Accepted combinations are:
function
string function name
list of functions and/or function names, e.g. [np.sum, 'mean']
[np.sum, 'mean']
dict of axis labels -> functions, function names or list of such.
Can also accept a Numba JIT function with engine='numba' specified. Only passing a single function is supported with this engine.
engine='numba'
If the 'numba' engine is chosen, the function must be a user defined function with values and index as the first and second arguments respectively in the function signature. Each group’s index will be passed to the user defined function and optionally available for use.
'numba'
values
index
Changed in version 1.1.0.
Positional arguments to pass to func.
'cython' : Runs the function through C-extensions from cython.
'cython'
'numba' : Runs the function through JIT compiled code from numba.
None : Defaults to 'cython' or globally setting compute.use_numba
None
compute.use_numba
New in version 1.1.0.
For 'cython' engine, there are no accepted engine_kwargs
engine_kwargs
For 'numba' engine, the engine can accept nopython, nogil and parallel dictionary keys. The values must either be True or False. The default engine_kwargs for the 'numba' engine is {'nopython': True, 'nogil': False, 'parallel': False} and will be applied to the function
nopython
nogil
parallel
True
False
{'nopython': True, 'nogil': False, 'parallel': False}
Keyword arguments to be passed into func.
See also
Series.groupby.apply
Apply function func group-wise and combine the results together.
Series.groupby.transform
Series.aggregate
Transforms the Series on each group based on the given function.
Notes
When using engine='numba', there will be no “fall back” behavior internally. The group data and group index will be passed as numpy arrays to the JITed user defined function, and no alternative execution attempts will be tried.
Examples
>>> s = pd.Series([1, 2, 3, 4])
>>> s 0 1 1 2 2 3 3 4 dtype: int64
>>> s.groupby([1, 1, 2, 2]).min() 1 1 2 3 dtype: int64
>>> s.groupby([1, 1, 2, 2]).agg('min') 1 1 2 3 dtype: int64
>>> s.groupby([1, 1, 2, 2]).agg(['min', 'max']) min max 1 1 2 2 3 4
The output column names can be controlled by passing the desired column names and aggregations as keyword arguments.
>>> s.groupby([1, 1, 2, 2]).agg( ... minimum='min', ... maximum='max', ... ) minimum maximum 1 1 2 2 3 4