title: pandas groupby and rolling_apply ignoring NaNs
body: <p>I have a pandas dataframe and I want to calculate the rolling mean of a column (after a groupby clause). However, I want to exclude NaNs.</p>
  
  <p>For instance, if the groupby returns [2, NaN, 1], the result should be 1.5 while currently it returns NaN.</p>
  
  <p>I've tried the following but it doesn't seem to work:</p>
  
  <pre><code>df.groupby(by=['var1'])['value'].apply(pd.rolling_apply, 3,  lambda x: np.mean([i for i in x if i is not np.nan and i!='NaN']))
  </code></pre>
  
  <p>If I even try this:</p>
  
  <pre><code>df.groupby(by=['var1'])['value'].apply(pd.rolling_apply, 3,  lambda x: 1)
  </code></pre>
  
  <p>I'm getting NaN in the output so it must be something to do with how pandas works in the background.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT:
  Here is a code sample with what I'm trying to do:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  df = pd.DataFrame({'var1' : ['a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'], 'value' : [1, 2, 3, np.nan, 2, 3, 4, 1] })
  print df.groupby(by=['var1'])['value'].apply(pd.rolling_apply, 2,  lambda x: np.mean([i for i in x if i is not np.nan and i!='NaN']))
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>0    NaN
  1    NaN
  2    2.0
  3    NaN
  4    2.5
  5    NaN
  6    3.0
  7    2.0
  </code></pre>
  
  <p>while I wanted to have the following:</p>
  
  <pre><code>0    NaN
  1    NaN
  2    2.0
  3    2.0
  4    2.5
  5    3.0
  6    3.0
  7    2.0
  </code></pre>