Skip to main content
`Ctrl`+`K`

# pandas.api.typing.Expanding.aggregate

Expanding.aggregate(func=None, *args, **kwargs)

  Aggregate using one or more operations over the specified axis.

  Parameters:
    func function, str, list or dict

      Function to use for aggregating the data. If a function, must either work when passed a Series/Dataframe or when passed to Series/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.

    *args

      Positional arguments to pass to func.

    **kwargs

      Keyword arguments to pass to func.

  Returns:
    scalar, Series or DataFrame

      The return can be:

      - scalar : when Series.agg is called with single function

      - Series : when DataFrame.agg is called with a single function

      - DataFrame : when DataFrame.agg is called with several functions

  See also

  `DataFrame.aggregate`

    Similar DataFrame method.

  `Series.aggregate`

    Similar Series method.

  Notes

  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.

  Functions that mutate the passed object can produce unexpected behavior or errors and are not supported. See Mutating with User Defined Function (UDF) methods for more details.

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

  If `func` defines an index relabeling, `axis` must be `0` or `index`.

  Examples

      >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
      >>> df
         A  B  C
      0  1  4  7
      1  2  5  8
      2  3  6  9

      >>> df.expanding(2).sum()
           A     B     C
      0  NaN   NaN   NaN
      1  3.0   9.0  15.0
      2  6.0  15.0  24.0

      >>> df.expanding(2).agg({"A": "sum", "B": "min"})
           A    B
      0  NaN  NaN
      1  3.0  4.0
      2  6.0  4.0