Different std in pandas vs numpy
In a nutshell, neither is "incorrect". Pandas uses the unbiased estimator (N-1
in the denominator), whereas Numpy by default does not.
To make them behave the same, pass ddof=1
to numpy.std()
.
For further discussion, see
- Can someone explain biased/unbiased population/sample standard deviation?
- Population variance and sample variance.
- Why divide by n-1?
For pandas
to performed the same as numpy
, you can pass in the ddof=0
parameter, so df.std(ddof=0)
.
This short video explains quite well why n-1
might be preferred for samples. https://www.youtube.com/watch?v=Cn0skMJ2F3c