Exponentially weighted smoothing
Smooth noisy measurements or financial series while emphasizing recent observations.
Pandas · Module
Creates an exponentially weighted window for DataFrame calculations. Supply a decay definition and then apply an operation such as mean() or std().
Calling ewm creates an exponentially weighted window over the DataFrame. Choose one decay specification, then call a window operation such as mean(); adjust, missing-value handling, minimum observations, time-based decay, and execution method control the calculation.
DataFrame.ewm(com=None, span=None, halflife=None, alpha=None, min_periods=0, adjust=True, ignore_na=False, times=None, method='single')| Name | Type | Description |
|---|---|---|
com | float, optional | Center-of-mass decay; requires com >= 0. |
span | float, optional | Span-based decay; requires span >= 1. |
halflife | float, str, timedelta, optional | Half-life decay; accepts a positive numeric or time-like value. |
alpha | float, optional | Direct smoothing factor; 0 < alpha <= 1. |
min_periods | int, default 0 | Minimum observations required; default 0. |
adjust | bool, default True | Whether to use the decaying adjustment factor; default True. |
ignore_na | bool, default False | Whether missing observations affect relative positions; default False. |
times | str, datetime-like, Series, optional | Observation times used for time-aware decay. |
method | {'single', 'table'}, default 'single' | Execution strategy; default 'single'. |
An exponentially weighted window object supporting exponentially weighted calculations.
com expresses decay using center of mass; its documented relationship is = 1 / (1 + com).span expresses decay using span and is converted into the smoothing factor.halflife expresses how quickly weights decay by defining a half-life.alpha lets callers provide the smoothing factor without converting from another decay representation.adjust=True, early periods are normalized with a decaying adjustment factor.times, supplying none or more than one of the four decay parameters is invalid.adjust=False require halflife alone as the decay specification.times and adjust=True, halflife can be combined with at most one alternative decay parameter.import pandas as pd
df = pd.DataFrame({"price": [10, 12, 11, 15]})
result = df.ewm(span=3, adjust=False).mean()
print(result)Creates an exponentially weighted moving mean where span controls decay and earlier values receive progressively less weight.
Smooth noisy measurements or financial series while emphasizing recent observations.
Use timestamps when observations are irregularly spaced and decay should reflect elapsed time.
Configure startup behavior and missing-value treatment for a moving calculation.
ewm returns an exponentially weighted window object rather than the aggregated values immediately. Calling methods such as mean() performs the requested exponentially weighted calculation.
Follow-up: How can decay be specified? Use exactly one of com, span, halflife, or alpha when times is absent; with time-aware calculations, halflife has special combination rules.
The decay can be expressed through center of mass, span, half-life, or the smoothing factor directly. The method then applies that weighting to operations such as the exponentially weighted mean.
Follow-up: Which direct smoothing-factor constraint applies? alpha must satisfy the documented range greater than zero and less than or equal to one.
times supplies timestamps corresponding to observations, enabling time-based decay through halflife. The permitted decay-parameter combinations depend on whether adjust is true or false.
Follow-up: What restriction applies when adjust=False? halflife must be the only decay-specification parameter when times is provided.
pandas.api.typing.ExponentialMovingWindow.meanpandas.api.typing.ExponentialMovingWindow.stdpandas.api.typing.DataFrameGroupBy.ewmDataFrame.rolling