pandas.core.groupby.DataFrameGroupBy.expanding#
- DataFrameGroupBy.expanding(*args, **kwargs)[source]#
Return an expanding grouper, providing expanding functionality per group.
Arguments are the same as :meth:DataFrame.rolling except that
step
cannot be specified.- Parameters:
- *argstuple
Positional arguments passed to the expanding window constructor.
- **kwargsdict
Keyword arguments passed to the expanding window constructor.
- Returns:
- pandas.api.typing.ExpandingGroupby
An object that supports expanding transformations over each group.
See also
Series.expanding
Expanding transformations for Series.
DataFrame.expanding
Expanding transformations for DataFrames.
Series.groupby
Apply a function groupby to a Series.
DataFrame.groupby
Apply a function groupby.
Examples
>>> df = pd.DataFrame( ... { ... "Class": ["A", "A", "A", "B", "B", "B"], ... "Value": [10, 20, 30, 40, 50, 60], ... } ... ) >>> df Class Value 0 A 10 1 A 20 2 A 30 3 B 40 4 B 50 5 B 60
>>> df.groupby("Class").expanding().mean() Value Class A 0 10.0 1 15.0 2 20.0 B 3 40.0 4 45.0 5 50.0