Skip to content

Commit 183b327

Browse files
authored
DOC: Add documentation for groupby.ewm() (#61283)
* updated doc and references * precommit * shortened summary * updated according to reviewer suggestions and removed test.py * Fixed docstring error
1 parent 24d31b7 commit 183b327

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

Diff for: doc/source/reference/groupby.rst

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Function application
7979
DataFrameGroupBy.cumsum
8080
DataFrameGroupBy.describe
8181
DataFrameGroupBy.diff
82+
DataFrameGroupBy.ewm
8283
DataFrameGroupBy.ffill
8384
DataFrameGroupBy.first
8485
DataFrameGroupBy.head
@@ -130,6 +131,7 @@ Function application
130131
SeriesGroupBy.cumsum
131132
SeriesGroupBy.describe
132133
SeriesGroupBy.diff
134+
SeriesGroupBy.ewm
133135
SeriesGroupBy.ffill
134136
SeriesGroupBy.first
135137
SeriesGroupBy.head

Diff for: pandas/core/groupby/groupby.py

+66-2
Original file line numberDiff line numberDiff line change
@@ -3824,15 +3824,79 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby:
38243824
)
38253825

38263826
@final
3827-
@Substitution(name="groupby")
3828-
@Appender(_common_see_also)
38293827
def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby:
38303828
"""
38313829
Return an ewm grouper, providing ewm functionality per group.
38323830
3831+
Parameters
3832+
----------
3833+
*args : tuple
3834+
Positional arguments passed to the EWM window constructor.
3835+
**kwargs : dict
3836+
Keyword arguments passed to the EWM window constructor, such as:
3837+
3838+
com : float, optional
3839+
Specify decay in terms of center of mass.
3840+
``span``, ``halflife``, and ``alpha`` are alternative ways to specify
3841+
decay.
3842+
span : float, optional
3843+
Specify decay in terms of span.
3844+
halflife : float, optional
3845+
Specify decay in terms of half-life.
3846+
alpha : float, optional
3847+
Specify smoothing factor directly.
3848+
min_periods : int, default 0
3849+
Minimum number of observations in the window required to have a value;
3850+
otherwise, result is ``np.nan``.
3851+
adjust : bool, default True
3852+
Divide by decaying adjustment factor to account for imbalance in
3853+
relative weights.
3854+
ignore_na : bool, default False
3855+
Ignore missing values when calculating weights.
3856+
times : str or array-like of datetime64, optional
3857+
Times corresponding to the observations.
3858+
axis : {0 or 'index', 1 or 'columns'}, default 0
3859+
Axis along which the EWM function is applied.
3860+
38333861
Returns
38343862
-------
38353863
pandas.api.typing.ExponentialMovingWindowGroupby
3864+
An object that supports exponentially weighted moving transformations over
3865+
each group.
3866+
3867+
See Also
3868+
--------
3869+
Series.ewm : EWM transformations for Series.
3870+
DataFrame.ewm : EWM transformations for DataFrames.
3871+
Series.groupby : Apply a function groupby to a Series.
3872+
DataFrame.groupby : Apply a function groupby.
3873+
3874+
Examples
3875+
--------
3876+
>>> df = pd.DataFrame(
3877+
... {
3878+
... "Class": ["A", "A", "A", "B", "B", "B"],
3879+
... "Value": [10, 20, 30, 40, 50, 60],
3880+
... }
3881+
... )
3882+
>>> df
3883+
Class Value
3884+
0 A 10
3885+
1 A 20
3886+
2 A 30
3887+
3 B 40
3888+
4 B 50
3889+
5 B 60
3890+
3891+
>>> df.groupby("Class").ewm(com=0.5).mean()
3892+
Value
3893+
Class
3894+
A 0 10.000000
3895+
1 17.500000
3896+
2 26.153846
3897+
B 3 40.000000
3898+
4 47.500000
3899+
5 56.153846
38363900
"""
38373901
from pandas.core.window import ExponentialMovingWindowGroupby
38383902

0 commit comments

Comments
 (0)