Skip to content

Commit f463546

Browse files
committed
DOC: Added docs for groupby.ewm() #61283
1 parent bbf5e2b commit f463546

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

pandas/core/groupby/groupby.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,35 +3835,38 @@ def ewm(
38353835
min_periods: int = 0,
38363836
adjust: bool = True,
38373837
ignore_na: bool = False,
3838-
axis: Axis = 0,
3838+
axis: int = 0,
38393839
) -> ExponentialMovingWindowGroupby:
38403840
"""
3841-
Return an exponential weighted moving average grouper, providing ewm functionality per group.
3841+
Return an exponential weighted moving average grouper,
3842+
providing ewm functionality per group.
38423843
38433844
Parameters
38443845
----------
38453846
com : float, optional
38463847
Specify decay in terms of center of mass:
38473848
:math:`\\alpha = 1 / (1 + com)` for :math:`com \\geq 0`.
3848-
3849-
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must be provided.
3849+
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3850+
be provided.
38503851
38513852
span : float, optional
38523853
Specify decay in terms of span:
38533854
:math:`\\alpha = 2 / (span + 1)` for :math:`span \\geq 1`.
3854-
3855-
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must be provided.
3855+
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3856+
be provided.
38563857
38573858
halflife : float, optional
38583859
Specify decay in terms of half-life:
38593860
:math:`\\alpha = 1 - \\exp(-\\ln(2) / halflife)` for :math:`halflife > 0`.
3860-
3861-
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must be provided.
3861+
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3862+
be provided.
38623863
38633864
alpha : float, optional
3864-
Specify the smoothing factor :math:`\\alpha` directly, where :math:`0 < \\alpha \\leq 1`.
3865-
3866-
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must be provided.
3865+
Specify the smoothing factor
3866+
:math:`\\alpha` directly, where :math:`0 < \\alpha \\leq 1`.
3867+
3868+
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3869+
be provided.
38673870
38683871
min_periods : int, default 0
38693872
Minimum number of observations in window required to have a value;
@@ -3872,26 +3875,27 @@ def ewm(
38723875
adjust : bool, default True
38733876
Divide by decaying adjustment factor in beginning periods to account
38743877
for imbalance in relative weightings (viewing EWMA as a moving average).
3875-
3878+
38763879
If ``False``, the exponentially weighted function is:
3877-
3880+
38783881
.. math::
38793882
y_t = (1 - \\alpha) y_{t-1} + \\alpha x_t
3880-
3883+
38813884
If ``True``, the exponentially weighted function is:
3882-
3885+
38833886
.. math::
38843887
y_t = \\frac{\\sum_{i=0}^t w_i x_{t-i}}{\\sum_{i=0}^t w_i}
3885-
3888+
38863889
where :math:`w_i = (1 - \\alpha)^i`.
38873890
38883891
ignore_na : bool, default False
38893892
If ``True``, missing values are ignored in the calculation.
3890-
3893+
38913894
If ``False``, missing values are treated as missing.
38923895
38933896
axis : {0 or 'index', 1 or 'columns'}, default 0
3894-
The axis to use. The value 0 identifies the rows, and 1 identifies the columns.
3897+
The axis to use. The value 0 identifies the rows, and 1 identifies the
3898+
columns.
38953899
38963900
Returns
38973901
-------
@@ -3917,7 +3921,7 @@ def ewm(
39173921
39183922
where :math:`\\alpha` is the smoothing factor derived from one of the input
39193923
decay parameters (``com``, ``span``, ``halflife``, or ``alpha``).
3920-
3924+
39213925
Only one of ``com``, ``span``, ``halflife``, or ``alpha`` can be specified.
39223926
39233927
Examples
@@ -3939,7 +3943,7 @@ def ewm(
39393943
39403944
>>> df.groupby("Class").ewm(span=2).mean()
39413945
Value
3942-
Class
3946+
Class
39433947
A 0 10.000000
39443948
1 17.500000
39453949
2 26.153846
@@ -3949,7 +3953,7 @@ def ewm(
39493953
39503954
>>> df.groupby("Class").ewm(alpha=0.5, adjust=False).mean()
39513955
Value
3952-
Class
3956+
Class
39533957
A 0 10.0
39543958
1 15.0
39553959
2 22.5
@@ -3959,7 +3963,7 @@ def ewm(
39593963
39603964
>>> df.groupby("Class").ewm(com=1.0, min_periods=1).std()
39613965
Value
3962-
Class
3966+
Class
39633967
A 0 NaN
39643968
1 7.071068
39653969
2 9.636241
@@ -3972,9 +3976,15 @@ def ewm(
39723976

39733977
return ExponentialMovingWindowGroupby(
39743978
self._selected_obj,
3975-
*args,
3979+
com=com,
3980+
span=span,
3981+
halflife=halflife,
3982+
alpha=alpha,
3983+
min_periods=min_periods,
3984+
adjust=adjust,
3985+
ignore_na=ignore_na,
3986+
axis=axis,
39763987
_grouper=self._grouper,
3977-
**kwargs,
39783988
)
39793989

39803990
@final

0 commit comments

Comments
 (0)