@@ -3828,8 +3828,7 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby:
3828
3828
@Appender (_common_see_also )
3829
3829
def ewm (self , * args , ** kwargs ) -> ExponentialMovingWindowGroupby :
3830
3830
"""
3831
- Return an exponential weighted moving average grouper,
3832
- providing ewm functionality per group.
3831
+ Provide exponential weighted functions for the groupby.
3833
3832
3834
3833
Parameters
3835
3834
----------
@@ -3838,54 +3837,34 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
3838
3837
:math:`\\ alpha = 1 / (1 + com)` for :math:`com \\ geq 0`.
3839
3838
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3840
3839
be provided.
3841
-
3842
3840
span : float, optional
3843
3841
Specify decay in terms of span:
3844
3842
:math:`\\ alpha = 2 / (span + 1)` for :math:`span \\ geq 1`.
3845
3843
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3846
3844
be provided.
3847
-
3848
3845
halflife : float, optional
3849
3846
Specify decay in terms of half-life:
3850
3847
:math:`\\ alpha = 1 - \\ exp(-\\ ln(2) / halflife)` for :math:`halflife > 0`.
3851
3848
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3852
3849
be provided.
3853
-
3854
3850
alpha : float, optional
3855
- Specify the smoothing factor
3856
- :math:`\\ alpha` directly, where :math:`0 < \\ alpha \\ leq 1`.
3857
-
3851
+ Specify the smoothing factor :math:`\\ alpha` directly, where :math:`0 < \\ alpha \\ leq 1`.
3858
3852
One and only one of ``com``, ``span``, ``halflife``, or ``alpha`` must
3859
3853
be provided.
3860
-
3861
3854
min_periods : int, default 0
3862
3855
Minimum number of observations in window required to have a value;
3863
3856
otherwise, result is ``np.nan``.
3864
-
3865
3857
adjust : bool, default True
3866
3858
Divide by decaying adjustment factor in beginning periods to account
3867
3859
for imbalance in relative weightings (viewing EWMA as a moving average).
3868
-
3869
- If ``False``, the exponentially weighted function is:
3870
-
3871
- .. math::
3872
- y_t = (1 - \\ alpha) y_{t-1} + \\ alpha x_t
3873
-
3874
- If ``True``, the exponentially weighted function is:
3875
-
3876
- .. math::
3877
- y_t = \\ frac{\\ sum_{i=0}^t w_i x_{t-i}}{\\ sum_{i=0}^t w_i}
3878
-
3879
- where :math:`w_i = (1 - \\ alpha)^i`.
3880
-
3881
3860
ignore_na : bool, default False
3882
3861
If ``True``, missing values are ignored in the calculation.
3883
-
3884
3862
If ``False``, missing values are treated as missing.
3885
-
3886
3863
axis : {0 or 'index', 1 or 'columns'}, default 0
3887
3864
The axis to use. The value 0 identifies the rows, and 1 identifies the
3888
3865
columns.
3866
+ *args, **kwargs
3867
+ Additional arguments and keyword arguments passed to the function.
3889
3868
3890
3869
Returns
3891
3870
-------
@@ -3897,15 +3876,12 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
3897
3876
Each group is treated independently, and the exponential weighted calculations
3898
3877
are applied separately to each group.
3899
3878
3900
- The exponential weighted calculation is based on the formula:
3901
-
3902
- .. math::
3903
- y_t = (1 - \\ alpha) y_{t-1} + \\ alpha x_t
3879
+ When ``adjust=True``, weighted averages are calculated using weights
3880
+ :math:`w_i = (1-\\ alpha)^i` where :math:`i` is the number of periods from the
3881
+ observations being weighted to the current period.
3904
3882
3905
- where :math:`\\ alpha` is the smoothing factor derived from one of the input
3906
- decay parameters (``com``, ``span``, ``halflife``, or ``alpha``).
3907
-
3908
- Only one of ``com``, ``span``, ``halflife``, or ``alpha`` can be specified.
3883
+ When ``adjust=False``, the calculation follows the recursive formula:
3884
+ :math:`y_t = (1 - \\ alpha) y_{t-1} + \\ alpha x_t`.
3909
3885
3910
3886
Examples
3911
3887
--------
@@ -3916,7 +3892,7 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
3916
3892
... }
3917
3893
... )
3918
3894
>>> df
3919
- Class Value
3895
+ Class Value
3920
3896
0 A 10
3921
3897
1 A 20
3922
3898
2 A 30
@@ -3925,7 +3901,7 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
3925
3901
5 B 60
3926
3902
3927
3903
>>> df.groupby("Class").ewm(span=2).mean()
3928
- Value
3904
+ Value
3929
3905
Class
3930
3906
A 0 10.000000
3931
3907
1 17.500000
@@ -3935,7 +3911,7 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
3935
3911
5 56.153846
3936
3912
3937
3913
>>> df.groupby("Class").ewm(alpha=0.5, adjust=False).mean()
3938
- Value
3914
+ Value
3939
3915
Class
3940
3916
A 0 10.0
3941
3917
1 15.0
0 commit comments