Skip to content

DataFrame.groupby(level=...).rolling(n).mean() #14420

@691175002

Description

@691175002

Using the groupby().rolling() object seems to duplicate a level of the index.

In [9]: d.groupby(level='ticker').rolling(30).mean()
Out[9]: 
ticker  ticker  date      
BMO     BMO     2006-01-02          NaN
                2006-01-03          NaN

TD      TD      2016-09-22    57.139340
                2016-09-23    57.171864


In [10]: d.groupby(level='ticker').apply(pd.rolling_mean, 30)
Out[10]: 
ticker  date      
BMO     2006-01-02          NaN
        2006-01-03          NaN

TD      2016-09-22    57.139340
        2016-09-23    57.171864


In [11]: d.groupby(level='ticker').apply(lambda x: x.rolling(30).mean())
Out[11]: 
ticker  date      
BMO     2006-01-02          NaN
        2006-01-03          NaN

TD      2016-09-22    57.139340
        2016-09-23    57.171864

I would expect the output to be the same in all three cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDuplicate ReportDuplicate issue or pull requestGroupbyReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions