Skip to content

Rolling window and np.nanmean outputs only NaN #14517

Closed
@ngenain

Description

@ngenain

Hi,

I am having an issue with the rolling apply method combinated with numpy's nanmean method. Here is my isssue:

import pandas as pd
import numpy as np

>>> df = pd.DataFrame({'A': [np.nan, np.nan, np.nan, 5, np.nan, np.nan]})
>>> df
     A
0  NaN
1  NaN
2  NaN
3  5.0
4  NaN
5  NaN

>>> df.rolling(3).apply(np.nanmean)
    A
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN

Expected Output

After index 3 I was expecting to see 5 in every line, how come I got only Nan?

Thanks for your help!

Output of pd.show_versions()

# Paste the output here ## INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-100-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.19.0
nose: 1.3.7
pip: 8.1.2
setuptools: 24.0.3
Cython: None
numpy: 1.11.2
scipy: 0.18.0
statsmodels: 0.6.1
xarray: None
IPython: 5.0.0
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions