Skip to content

Unexpected result from rolling_median when center = True #5549

Closed
@jonblunt

Description

@jonblunt
s = pd.Series( range(10), index = pd.PeriodIndex(start = '2013-10-1', end = '2013-10-10', freq = 'D'))
pd.rolling_median(s,5,  min_periods = 1)

2013-10-01    0.0
2013-10-02    0.5
2013-10-03    1.0
2013-10-04    1.5
2013-10-05    2.0
2013-10-06    3.0
2013-10-07    4.0
2013-10-08    5.0
2013-10-09    6.0
2013-10-10    7.0
Freq: D, dtype: float64

When center is specified we get Nans in the last window//2 positions

s = pd.Series( range(10), index = pd.PeriodIndex(start = '2013-10-1', end = '2013-10-10', freq = 'D'))
pd.rolling_median(s,5,  min_periods = 1, center = True)

2013-10-01    1.0
2013-10-02    1.5
2013-10-03    2.0
2013-10-04    3.0
2013-10-05    4.0
2013-10-06    5.0
2013-10-07    6.0
2013-10-08    7.0
2013-10-09    NaN
2013-10-10    NaN
Freq: D, dtype: float64

I was expecting the last two values to be 7.5 and 8.

I got the same results, nans at the end with rolling_mean as well

This is with pandas 12.0 and windows 64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions