Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.ewm

Creates an exponentially weighted window for DataFrame calculations. Supply a decay definition and then apply an operation such as mean() or std().

How it works

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.

Syntax

DataFrame.ewm(com=None, span=None, halflife=None, alpha=None, min_periods=0, adjust=True, ignore_na=False, times=None, method='single')

Parameters

NameTypeDescription
comfloat, optionalCenter-of-mass decay; requires com >= 0.
spanfloat, optionalSpan-based decay; requires span >= 1.
halflifefloat, str, timedelta, optionalHalf-life decay; accepts a positive numeric or time-like value.
alphafloat, optionalDirect smoothing factor; 0 < alpha <= 1.
min_periodsint, default 0Minimum observations required; default 0.
adjustbool, default TrueWhether to use the decaying adjustment factor; default True.
ignore_nabool, default FalseWhether missing observations affect relative positions; default False.
timesstr, datetime-like, Series, optionalObservation times used for time-aware decay.
method{'single', 'table'}, default 'single'Execution strategy; default 'single'.

Returns

An exponentially weighted window object supporting exponentially weighted calculations.

Key points

  • The method creates an exponentially weighted window for DataFrame 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.
  • With adjust=True, early periods are normalized with a decaying adjustment factor.

Common mistakes

  • Without times, supplying none or more than one of the four decay parameters is invalid.
  • Time-aware windows with adjust=False require halflife alone as the decay specification.
  • With times and adjust=True, halflife can be combined with at most one alternative decay parameter.

Example: Exponentially weighted moving mean

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.

When to use it

Exponentially weighted smoothing

Smooth noisy measurements or financial series while emphasizing recent observations.

Time-aware decay

Use timestamps when observations are irregularly spaced and decay should reflect elapsed time.

Control weighting behavior

Configure startup behavior and missing-value treatment for a moving calculation.

Interview questions

QWhat does DataFrame.ewm return and how is it used?

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.

QHow can the decay rate be configured?

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.

QWhen would you use the times parameter?

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.mean
  • pandas.api.typing.ExponentialMovingWindow.std
  • pandas.api.typing.DataFrameGroupBy.ewm
  • DataFrame.rolling

Source: pandas.DataFrame.ewm. Checked 2026-10-15.