What is the statistics.pstdev() method in Python?

Overview

The statistics.pstdev() method in Python returns the population standard deviation. This method is unlike the statistics.stdev() method, which only calculates the standard deviation from a sample of data, and instead calculates the standard deviation of an entire population.

Standard deviation is simply the square root of variance or the sample variance and is found by:

standard deviation = √variance

Syntax

statistics.pstdev(data, xbar)

Parameter value

Parameter

Function

data

This is a required argument. It is the data to be used. It can be a list, a sequence, or an iterator.

xbar

This is an optional argument. It is the mean of the data provided. If the value is not provided, by default, Python calculates the mean of the data.

Return value

The statistics.pstdev() method returns a float value, which represents the population standard deviation of a given data.

Code example

Let’s use the statistics.pstdev() method to calculate the population standard deviation for the given data.

import statistics
# creating a data set
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# to obtain the population standard deviation
p_standard_deviation = statistics.pstdev(data)
print('The population standard deviation is', p_standard_deviation)

Code explanation

  • Line 1: We imported the statistics module.
  • Line 4: We created a data set we called data.
  • Line 6: We used the statistics.pstdev() method to obtain the population standard deviation of the data variable and assigned the value to another variable, p_standard_deviation.
  • Line 7: We printed p_standard_deviation, which contains the population standard deviation of the given data.

Free Resources