title: How to ignore NaN in rolling average calculation in Python
body: <p>For a time series sales forecasting task I want to create a feature that represents the average sales over the last 3 days. I have a problem when I want to predict the sales for days in the future, since these data points do not have sales data (NaN values). Pandas offers rolling_mean(), but that function results in a NaN ouput when any data point in the window is NaN. </p>
  
  <p>My data:</p>
  
  <pre><code>Date    Sales
  02-01-2013  100.0
  03-01-2013  200.0
  04-01-2013  300.0
  05-01-2013  200.0
  06-01-2013  NaN
  </code></pre>
  
  <p>Result after using pd.rolling_mean() with window of 2:</p>
  
  <pre><code>Date    Rolling_Sales
  02-01-2013  NaN
  03-01-2013  150.0
  04-01-2013  250.0
  05-01-2013  250.0
  06-01-2013  NaN
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>Date    Rolling_Sales
  02-01-2013  NaN
  03-01-2013  150.0
  04-01-2013  250.0
  05-01-2013  250.0
  06-01-2013  200.0
  </code></pre>
  
  <p>So in case the a NaN is included, I want to ignore it and take the average of all the other data points in the window.</p>