title: how to zscore normalize pandas column with nans?
body: <p>I have a pandas dataframe with a column of real values that I want to zscore normalize:</p>
  
  <pre><code>&gt;&gt; a
  array([    nan,  0.0767,  0.4383,  0.7866,  0.8091,  0.1954,  0.6307,
          0.6599,  0.1065,  0.0508])
  &gt;&gt; df = pandas.DataFrame({"a": a})
  </code></pre>
  
  <p>The problem is that a single <code>nan</code> value makes all the array <code>nan</code>:</p>
  
  <pre><code>&gt;&gt; from scipy.stats import zscore
  &gt;&gt; zscore(df["a"])
  array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan])
  </code></pre>
  
  <p>What's the correct way to apply <code>zscore</code> (or an equivalent function not from scipy) to a column of a pandas dataframe and have it ignore the <code>nan</code> values? I'd like it to be same dimension as original column with <code>np.nan</code> for values that can't be normalized</p>
  
  <p><strong>edit</strong>: maybe the best solution is to use <code>scipy.stats.nanmean</code> and <code>scipy.stats.nanstd</code>? I don't see why the degrees of freedom need to be changed for <code>std</code> for this purpose:</p>
  
  <pre><code>zscore = lambda x: (x - scipy.stats.nanmean(x)) / scipy.stats.nanstd(x)
  </code></pre>