Skip to content

Commit 52e9767

Browse files
authored
DOC: Add documentation for groupby.expanding() (#61274)
1 parent 183b327 commit 52e9767

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Function application
8080
DataFrameGroupBy.describe
8181
DataFrameGroupBy.diff
8282
DataFrameGroupBy.ewm
83+
DataFrameGroupBy.expanding
8384
DataFrameGroupBy.ffill
8485
DataFrameGroupBy.first
8586
DataFrameGroupBy.head
@@ -132,6 +133,7 @@ Function application
132133
SeriesGroupBy.describe
133134
SeriesGroupBy.diff
134135
SeriesGroupBy.ewm
136+
SeriesGroupBy.expanding
135137
SeriesGroupBy.ffill
136138
SeriesGroupBy.first
137139
SeriesGroupBy.head

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

+46-4
Original file line numberDiff line numberDiff line change
@@ -3803,16 +3803,58 @@ def rolling(
38033803
)
38043804

38053805
@final
3806-
@Substitution(name="groupby")
3807-
@Appender(_common_see_also)
38083806
def expanding(self, *args, **kwargs) -> ExpandingGroupby:
38093807
"""
3810-
Return an expanding grouper, providing expanding
3811-
functionality per group.
3808+
Return an expanding grouper, providing expanding functionality per group.
3809+
3810+
Arguments are the same as `:meth:DataFrame.rolling` except that ``step`` cannot
3811+
be specified.
3812+
3813+
Parameters
3814+
----------
3815+
*args : tuple
3816+
Positional arguments passed to the expanding window constructor.
3817+
**kwargs : dict
3818+
Keyword arguments passed to the expanding window constructor.
38123819
38133820
Returns
38143821
-------
38153822
pandas.api.typing.ExpandingGroupby
3823+
An object that supports expanding transformations over each group.
3824+
3825+
See Also
3826+
--------
3827+
Series.expanding : Expanding transformations for Series.
3828+
DataFrame.expanding : Expanding transformations for DataFrames.
3829+
Series.groupby : Apply a function groupby to a Series.
3830+
DataFrame.groupby : Apply a function groupby.
3831+
3832+
Examples
3833+
--------
3834+
>>> df = pd.DataFrame(
3835+
... {
3836+
... "Class": ["A", "A", "A", "B", "B", "B"],
3837+
... "Value": [10, 20, 30, 40, 50, 60],
3838+
... }
3839+
... )
3840+
>>> df
3841+
Class Value
3842+
0 A 10
3843+
1 A 20
3844+
2 A 30
3845+
3 B 40
3846+
4 B 50
3847+
5 B 60
3848+
3849+
>>> df.groupby("Class").expanding().mean()
3850+
Value
3851+
Class
3852+
A 0 10.0
3853+
1 15.0
3854+
2 20.0
3855+
B 3 40.0
3856+
4 45.0
3857+
5 50.0
38163858
"""
38173859
from pandas.core.window import ExpandingGroupby
38183860

0 commit comments

Comments
 (0)