Skip to content

Commit c12bbe0

Browse files
committed
Added docstring and to groupby.rst
1 parent adec21f commit c12bbe0

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

doc/source/reference/groupby.rst

Lines changed: 2 additions & 0 deletions
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.expanding
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.expanding
133135
SeriesGroupBy.ffill
134136
SeriesGroupBy.first
135137
SeriesGroupBy.head

pandas/core/groupby/groupby.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,12 +3807,51 @@ def rolling(
38073807
@Appender(_common_see_also)
38083808
def expanding(self, *args, **kwargs) -> ExpandingGroupby:
38093809
"""
3810-
Return an expanding grouper, providing expanding
3810+
Return an expanding grouper, providing expanding (cumulative)
38113811
functionality per group.
38123812
3813+
Parameters
3814+
----------
3815+
min_periods : int, default 1
3816+
Minimum number of observations in the window required to have a value;
3817+
otherwise, the result is ``np.nan``.
3818+
38133819
Returns
38143820
-------
3815-
pandas.api.typing.ExpandingGroupby
3821+
pandas.core.window.ExpandingGroupby
3822+
An object that supports expanding transformations over each group.
3823+
3824+
See Also
3825+
--------
3826+
Series.expanding : Expanding transformations for Series.
3827+
DataFrame.expanding : Expanding transformations for DataFrames.
3828+
Series.groupby : Apply a function groupby to a Series.
3829+
DataFrame.groupby : Apply a function groupby.
3830+
3831+
Examples
3832+
--------
3833+
>>> import pandas as pd
3834+
>>> df = pd.DataFrame({
3835+
... "Class": ["A", "A", "A", "B", "B", "B"],
3836+
... "Value": [10, 20, 30, 40, 50, 60]
3837+
... })
3838+
>>> df
3839+
Class Value
3840+
0 A 10
3841+
1 A 20
3842+
2 A 30
3843+
3 B 40
3844+
4 B 50
3845+
5 B 60
3846+
3847+
>>> df.groupby("Class").expanding().mean().reset_index(drop=True)
3848+
Value
3849+
0 10.0
3850+
1 15.0
3851+
2 20.0
3852+
3 40.0
3853+
4 45.0
3854+
5 50.0
38163855
"""
38173856
from pandas.core.window import ExpandingGroupby
38183857

0 commit comments

Comments
 (0)