pandas.core.window.expanding.Expanding.apply — pandas 3.0.0.dev0+2104.ge637b4290d documentation (original) (raw)

Expanding.apply(func, raw=False, engine=None, engine_kwargs=None, args=None, kwargs=None)[source]#

Calculate the expanding custom aggregation function.

Parameters:

funcfunction

Must produce a single value from an ndarray input if raw=Trueor a single value from a Series if raw=False. Can also accept a Numba JIT function with engine='numba' specified.

rawbool, default False

enginestr, default None

engine_kwargsdict, default None

argstuple, default None

Positional arguments to be passed into func.

kwargsdict, default None

Keyword arguments to be passed into func.

Returns:

Series or DataFrame

Return type is the same as the original object with np.float64 dtype.

See also

Series.expanding

Calling expanding with Series data.

DataFrame.expanding

Calling expanding with DataFrames.

Series.apply

Aggregating apply for Series.

DataFrame.apply

Aggregating apply for DataFrame.

Examples

ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) ser.expanding().apply(lambda s: s.max() - 2 * s.min()) a -1.0 b 0.0 c 1.0 d 2.0 dtype: float64