statistics.pstdev

Full name
statistics.pstdev
Library
statistics
Syntax

statistics.pstdev(data, mu = None)

Description

The statistics.pstdev function returns the standard deviation of the population composed of the elements in data.

Parameters
  • data: Iterable for whose elements you want to obtain the standard deviation.
  • mu: Optional argument. Value from which deviations are calculated. If omitted, they are obtained with respect to the mean value of the data.
Result

The statistics.pstdev function returns a real number.

Examples

We can obtain the standard deviation of the values of a list with the following code:

statistics.pstdev([1, 3, 3, 6])
1.7853571071357126

In this second example we are going to generate a list made up of a thousand random values extracted from a Gaussian distribution with mean 5 and standard deviation 1:

import random
y = [random.gauss(5, 1) for _ in range(1000)]

Let's show the histogram:

import matplotlib.pyplot as plt
plt.figure(figsize = (8, 4))
plt.hist(y, bins = 10)
plt.grid()
plt.show()
statistics.pstdev

Let's get its standard deviation below:

statistics.pstdev(y)
0.9770684423061939

If we specify the value 10 as mu argument, the deviations will be calculated with respect to this value:

statistics.pstdev(y, mu = 10)
5.032367764622201
Submitted by admin on Thu, 04/01/2021 - 10:59