Skip to content

ENH: support .groupby().ewm() directly #16037

Closed
@jreback

Description

@jreback

would be nice to support .groupby().ewm() directly.

In [2]: df = pd.DataFrame({'tid': np.random.randint(0, 10, size=100), 'value': np.random.randn(100)})

In [3]: df.groupby('tid').rolling(3).value.mean()
Out[3]: 
tid    
0    3          NaN
     6          NaN
     10   -0.596818
     16   -0.619943
     23   -0.688623
     24   -0.167816
             ...   
9    74    0.575155
     80    1.046240
     81    0.279683
     85    0.296154
     86   -0.267774
     92    0.320419
Name: value, dtype: float64

In [4]: df.groupby('tid').apply(lambda x: x.ewm(5).value.mean())
Out[4]: 
tid    
0    3    -1.182125
     6    -0.118510
     10   -0.616044
     16   -0.820601
     23   -0.435397
     24   -0.279619
             ...   
9    74    0.505610
     80    0.657754
     81    0.451367
     85    0.372517
     86    0.226676
     92    0.429832
Name: value, dtype: float64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions