Statistics
module in python contains different methods which are used to calculate mathematical and statistical analysis of numeric data. With this module, one can obtain and perform different mathematical operations involving numerical data.
There are various methods under the statistics
module which are used for the different statistical analysis. Some of these methods include:
mean()
method: to calculate the mean value of a data setstdev()
method: used to calculate the standard deviation of a data set.pstdev()
method: used to calculate the population standard deviation of a given data set.median()
method: used to calculate the median value of a data setmode()
method: to calculate the modal value of a data set.geometric_mean
method: used to calculate the geometric mean of a data set. etc.In this shot, we are taking a closer look at the statistics.stdev()
method.
The statistics.stdev()
method in python returns the standard deviation of a given data sample. This method is unlike the statistics.pstdev()
, which calculates the standard deviation of an entire population; instead, it only computes the standard deviation from a sample of data.
Standard deviation is simply the square root of variance or the sample variance and is given by:
standard deviation = √variance
statistics.stdev(data, xbar)
Parameter | Details |
| This is required argument. It is the data to be used. It can be a list, a sequence or iterator |
| This is optional. It is the mean of the data provided. If the value is not provided, by default, it calculates the mean of the data |
statistics.stdev()
method returns a float value which represents the standard deviation of a given data.
Let us use the statistics.stdev()
method to calculate the standard deviation for a given data as follows:
import statistics# creating a data setdata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]# to obtain the standard deviationstandard_deviation = statistics.stdev(data)print('The standard deviation is', standard_deviation)
statistics
modulestatistics.stdev()
method to obtain the standard deviation of the data and assigned the value to another variable standard_deviation.