One - One Code All

Blog Content

pandas中计算总体标准差

Python 统计学-科学计算   2016-04-30 19:25:05

标准差(或方差),分为 总体标准差(方差)和 样本标准差(方差)。
前者分母为n,后者为n-1。后者是无偏的。
pandas里的 .std() 和 .var() 都是算的无偏的。
而numpy是有偏的。
 
那么在pandas里想算有偏的(即总体标准差或总体方差),怎么做?
https://github.com/pydata/pandas/issues/1798
参考这里。
 
 下面的内容复制自上述链接:

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)

上面是无偏,下面是有偏。


上一篇:使用SSL 465端口发送邮件的Python脚本
下一篇:Python字典dictionary changed size during iteration

The minute you think of giving up, think of the reason why you held on so long.