Skip to content

incorrect calculation of centered moving averages for even length series #14425

@simonm3

Description

@simonm3

For even numbered periods the centered moving average is calculated incorrectly. Suppose the period length is 5. Then the center of 5 periods is 3. However if the period length is 4 then the center of the period is 2.5. The value at index 3 should be the average of the values at 2.5 and 3.5. Pandas is showing the 2.5 value at 3 which is incorrect.

EXAMPLE:
a=pd.Series(range(1,6), index=range(1,6))
a.rolling(4, center=True).mean()

1 NaN
2 NaN
3 2.5
4 3.5
5 NaN

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDuplicate ReportDuplicate issue or pull requestNeeds DiscussionRequires discussion from core team before further actionNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions