FB Style Menu

Saturday, July 2, 2022

Why Standard Deviation value defer from Numpy and Excel !!!

If you import numpy and find standard deviation value for 32,24,67,45,59,77,97, you will get below result.

 

import numpy

array = [32,24,67,45,59,77,97]

std = numpy.std(array)

print(std)

OUTPUT : 23.7890


The same array you put into excel worksheet and use excel formula (STDEV(A1:A7))

OUTPUT : 25.6951


What is the difference?

The difference is numpy std( ) function is calculated for Population data while excel STDEV formula is calculated for Sample data.



If we want to calculated Sample SD in python, we need to import "statistics" instead of "numpy", then used stdev( ) function. 

import statistics 

array = [32,24,67,45,59,77,97]

x = statistics.std(array)

print(x) 

OUTPUT :

25.695098661770018

23.78903880670547


Take away : 

If you need to calculate SD for Population data, use numpy.

If you need to calculate SD for Sample data, use statistics.










No comments:

Post a Comment