我写了一个python代码来计算数字列表的标准偏差。我检查了我对Excel的答案,它似乎是关闭的。我不确定我是否错过了一个步骤,或者我应该担心,但是如果有人有时间查看代码并查看他们是否发现错误,请告诉我。谢谢。Python标准偏差检查
city_population = [2123,1284,7031,30788,147,2217,10000]
mean = sum(city_population,0.0)/len(city_population)
def stdev(city_population):
length = len(city_population)
total_sum = 0
for i in range(length):
total_sum += pow((city_population[i]-mean),2)
result = (total_sum/(length-1))
return sqrt(result)
stan_dev = stdev(city_population)
print "The standard deviation is",(stan_dev)
输出: The standard deviation is 9443.71609738
的Excel:9986.83890663
你使用哪个excel函数? –
人口std dev –