title: What algorithm does Pandas use for computing variance?
body: <p>Which method does Pandas use for computing the variance of a Series?</p>
  
  <p>For example, using Pandas (v0.14.1):</p>
  
  <pre><code>pandas.Series(numpy.repeat(500111,2000000)).var()
  12.579462289731145
  </code></pre>
  
  <p>Obviously due to some numeric instability.  However, in R we get:</p>
  
  <pre><code>var(rep(500111,2000000))
  0
  </code></pre>
  
  <p>I wasn't able to make enough sense of the Pandas source-code to figure out what algorithm it uses.
  This link may be useful: <a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance" rel="nofollow">http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance</a></p>
  
  <p><strong>Update</strong>: To summarize the comments below - If the Python <a href="http://berkeleyanalytics.com/bottleneck/" rel="nofollow">bottleneck</a> package for fast NumPy array functions is installed, a stabler two-pass algorithm similar to <code>np.sqrt(((arr - arr.mean())**2).mean())</code> is used and gives 0.0 (as indicated by @Jeff); whereas if it is not installed, the naive implementation indicated by @BrenBarn is used.</p>