GroupBy.apply(self, func, *args, **kwargs)
[source]
Apply function func
group-wise and combine the results together.
The function passed to apply
must take a dataframe as its first argument and return a DataFrame, Series or scalar. apply
will then take care of combining the results back together into a single dataframe or series. apply
is therefore a highly flexible grouping method.
While apply
is a very flexible method, its downside is that using it can be quite a bit slower than using more specific methods like agg
or transform
. Pandas offers a wide range of method that will be much faster than using apply
for their specific purposes, so try to use them before reaching for apply
.
Parameters: |
|
---|---|
Returns: |
|
See also
pipe
aggregate
transform
Series.apply
DataFrame.apply
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.core.groupby.GroupBy.apply.html