Skip to content

DataFrame.rolling.mean resets windows with NaN #6550

@Loanwolf

Description

@Loanwolf

hello all,

I posted a question on SO a few days ago regarding unexpected behaviour with rolling_mean().

http://stackoverflow.com/questions/22146105/compute-a-sequential-rolling-mean-in-pandas-as-array-function

Looking at the sourse code this could have implications to a host functions that call rolling_mean(). Wondered what people's thought's were? Not sure if this could be called a bug but it certainly unexpected. Is it possible to implement a sparse option that uses the dropna() apply solution suggested behzad.nouri in the link ?

Regards and many thanks for all the hard work on this package

Copy paste example:

In [52]: import numpy as np ...: from pandas import * ...: ...: foo = DataFrame(np.arange(0.0,13.0)) ...: foo['1'] = np.arange(13.0,26.0) ...: foo.ix[4:6,0] = np.nan ...: foo.ix[4:7,1] = np.nan ...: ...: /anaconda3/envs/pandas-dev/bin/ipython:6: DeprecationWarning: .ix is deprecated. Please use .loc for label based indexing or .iloc for positional indexing See the documentation here: http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated /anaconda3/envs/pandas-dev/bin/ipython:7: DeprecationWarning: .ix is deprecated. Please use .loc for label based indexing or .iloc for positional indexing See the documentation here: http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated from IPython import start_ipython In [53]: foo.rolling(4).mean() Out[53]: 0 1 0 NaN NaN 1 NaN NaN 2 NaN NaN 3 1.5 14.5 4 NaN NaN 5 NaN NaN 6 NaN NaN 7 NaN NaN 8 NaN NaN 9 NaN NaN 10 8.5 NaN 11 9.5 22.5 12 10.5 23.5 

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions