pandas 1.4.2

NotesParametersReturnsBackRef
aggregate(self, func=None, axis: 'Axis' = 0, *args, **kwargs)

Notes

:None:None:`agg` is an alias for aggregate . Use the alias.

Functions that mutate the passed object can produce unexpected behavior or errors and are not supported. See gotchas.udf-mutation for more details.

A passed user-defined-function will be passed a Series for evaluation.

Parameters

func : function, str, list or dict

Function to use for aggregating the data. If a function, must either work when passed a DataFrame or when passed to DataFrame.apply.

Accepted combinations are:

  • function

  • string function name

  • list of functions and/or function names, e.g. [np.sum, 'mean']

  • dict of axis labels -> functions, function names or list of such.

axis : {0 or 'index', 1 or 'columns'}, default 0

If 0 or 'index': apply function to each column. If 1 or 'columns': apply function to each row.

*args :

Positional arguments to pass to func .

**kwargs :

Keyword arguments to pass to func .

Returns

scalar, Series or DataFrame

The return can be:

The aggregation operations are always performed over an axis, either the
index (default) or the column axis. This behavior is different from
`numpy` aggregation functions (`mean`, `median`, `prod`, `sum`, `std`,
`var`), where the default is to compute the aggregation of the flattened
array, e.g., ``numpy.mean(arr_2d)`` as opposed to
``numpy.mean(arr_2d, axis=0)``.
`agg` is an alias for `aggregate`. Use the alias.

Aggregate using one or more operations over the specified axis.

See Also

DataFrame.apply

Perform any type of operations.

DataFrame.transform

Perform transformation type operations.

core.groupby.GroupBy

Perform operations over groups.

core.resample.Resampler

Perform operations over resampled bins.

core.window.Expanding

Perform operations over expanding window.

core.window.ExponentialMovingWindow

Perform operation over exponential weighted window.

core.window.Rolling

Perform operations over rolling window.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame([[1, 2, 3],
...  [4, 5, 6],
...  [7, 8, 9],
...  [np.nan, np.nan, np.nan]],
...  columns=['A', 'B', 'C'])

Aggregate these functions over the rows.

This example is valid syntax, but we were not able to check execution
>>> df.agg(['sum', 'min'])
        A     B     C
sum  12.0  15.0  18.0
min   1.0   2.0   3.0

Different aggregations per column.

This example is valid syntax, but we were not able to check execution
>>> df.agg({'A' : ['sum', 'min'], 'B' : ['min', 'max']})
        A    B
sum  12.0  NaN
min   1.0  2.0
max   NaN  8.0

Aggregate different functions over the columns and rename the index of the resulting DataFrame.

This example is valid syntax, but we were not able to check execution
>>> df.agg(x=('A', max), y=('B', 'min'), z=('C', np.mean))
     A    B    C
x  7.0  NaN  NaN
y  NaN  2.0  NaN
z  NaN  NaN  6.0

Aggregate over the columns.

This example is valid syntax, but we were not able to check execution
>>> df.agg("mean", axis="columns")
0    2.0
1    5.0
2    8.0
3    NaN
dtype: float64
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.window.expanding.Expanding.aggregate pandas.core.frame.DataFrame.transform pandas.core.frame.DataFrame.aggregate pandas.core.frame.DataFrame.apply pandas.core.window.rolling.Window.aggregate

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#8634
type: <class 'function'>
Commit: