bigframes.pandas.api.typing.DataFrameGroupBy.agg#

DataFrameGroupBy.agg(func=None, **kwargs) DataFrame | Series[source]#

Aggregate using one or more operations.

Examples:

>>> data = {"A": [1, 1, 2, 2],
...         "B": [1, 2, 3, 4],
...         "C": [0.362838, 0.227877, 1.267767, -0.562860]}
>>> df = bpd.DataFrame(data)

The aggregation is for each column.

>>> df.groupby('A').agg('min')
    B         C
A
1  1  0.227877
2  3  -0.56286

[2 rows x 2 columns]

Multiple aggregations

>>> df.groupby('A').agg(['min', 'max'])
    B             C
       min max       min       max
A
1        1   2  0.227877  0.362838
2        3   4  -0.56286  1.267767

[2 rows x 4 columns]
Parameters:
  • func (function, str, list, dict or None) –

    Function to use for aggregating the data.

    Accepted combinations are:

    • string function name

    • list of function names, e.g. ['sum', 'mean']

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

    • None, in which case **kwargs are used with Named Aggregation. Here the output has one column for each element in **kwargs. The name of the column is keyword, whereas the value determines the aggregation used to compute the values in the column.

  • kwargs – If func is None, **kwargs are used to define the output names and aggregations via Named Aggregation. See func entry.

Returns:

A BigQuery DataFrame.

Return type:

bigframes.pandas.DataFrame