標准差(或方差),分為 總體標准差(方差)和 樣本標准差(方差)。
前者分母為n,后者為n-1。后者是無偏的。
pandas里的 .std() 和 .var() 都是算的無偏的。
而numpy是有偏的。
那么在pandas里想算有偏的(即總體標准差或總體方差),怎么做?
參考這里。
下面的內容復制自上述鏈接:
Pandas 0.8.1:
import pandas as pd
a=pd.Series([0, 1, 3, 6])
a.mean(), a.std(), a.var()
a.values.mean(), a.values.std(), a.values.var()
I would expect both last lines to return the same result. However, the former returned:
(2.5, 2.6457513110645907, 7.0)
and the latter:
(2.5, 2.2912878474779199, 5.25)
上面是無偏,下面是有偏。