pandas.api.typing.DataFrameGroupBy.ewm — pandas 3.0.0rc0+33.g1fd184de2a documentation (original) (raw)
DataFrameGroupBy.ewm(com=None, span=None, halflife=None, alpha=None, min_periods=0, adjust=True, ignore_na=False, times=None, method='single')[source]#
Return an ewm grouper, providing ewm functionality per group.
Parameters:
comfloat, optional
Specify decay in terms of center of mass. Alternative to span, halflife, and alpha.
spanfloat, optional
Specify decay in terms of span.
halflifefloat, str, or Timedelta, optional
Specify decay in terms of half-life.
alphafloat, optional
Specify smoothing factor directly.
min_periodsint, default 0
Minimum number of observations in the window required to have a value; otherwise, result is np.nan.
adjustbool, default True
Divide by decaying adjustment factor to account for imbalance in relative weights.
ignore_nabool, default False
Ignore missing values when calculating weights.
timesstr or array-like of datetime64, optional
Times corresponding to the observations.
method{‘single’, ‘table’}, default ‘single’
Execute the operation per group independently ('single') or over the entire object before regrouping ('table'). Only applicable tomean(), and only when using engine='numba'.
Returns:
pandas.api.typing.ExponentialMovingWindowGroupby
An object that supports exponentially weighted moving transformations over each group.
See also
Series.ewm
EWM transformations for Series.
DataFrame.ewm
EWM transformations for DataFrames.
Series.groupby
Apply a function groupby to a Series.
DataFrame.groupby
Apply a function groupby.
Examples
df = pd.DataFrame( ... { ... "Class": ["A", "A", "A", "B", "B", "B"], ... "Value": [10, 20, 30, 40, 50, 60], ... } ... ) df Class Value 0 A 10 1 A 20 2 A 30 3 B 40 4 B 50 5 B 60
df.groupby("Class").ewm(com=0.5).mean() Value Class A 0 10.000000 1 17.500000 2 26.153846 B 3 40.000000 4 47.500000 5 56.153846