我寫了一個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 –