Statistics Standard Deviation

Standard deviation measures how spread out the values in a dataset are around the mean, expressed in the same units as the original data.

What Does Standard Deviation Measure?

Two datasets can have exactly the same mean but look completely different. The mean alone does not tell you whether values are tightly clustered together or scattered widely. Standard deviation fills that gap by measuring, on average, how far each value sits from the mean.

Consider two delivery drivers whose average delivery time is 30 minutes. Driver A's times are 28, 29, 30, 31, and 32 minutes - very consistent. Driver B's times are 10, 20, 30, 40, and 50 minutes - wildly inconsistent, even though the average is also exactly 30. Standard deviation is what lets you say that Driver A is far more predictable than Driver B.

Calculating Standard Deviation Step by Step

  1. Find the mean of the dataset.
  2. Subtract the mean from each value to get its deviation.
  3. Square each deviation, so negative and positive deviations do not cancel out.
  4. Average the squared deviations - this average is called the variance.
  5. Take the square root of the variance to get the standard deviation, back in the original units.
Value (minutes)Deviation from MeanSquared Deviation
10-20400
20-10100
3000
4010100
5020400

Example

delivery_times = [10, 20, 30, 40, 50]  # minutes, Driver B

mean = sum(delivery_times) / len(delivery_times)

squared_diffs = []
for time in delivery_times:
    squared_diffs.append((time - mean) ** 2)

variance = sum(squared_diffs) / len(delivery_times)
std_dev = variance ** 0.5

print("Mean:", mean)
print("Variance:", variance)
print("Standard deviation:", round(std_dev, 2))
# Mean: 30.0
# Variance: 200.0
# Standard deviation: 14.14

Example

import statistics

delivery_times = [10, 20, 30, 40, 50]

print("Population std dev:", statistics.pstdev(delivery_times))
print("Sample std dev:", statistics.stdev(delivery_times))
# Population std dev: 14.142135623730951
# Sample std dev: 15.811388300841896

Population vs Sample Standard Deviation

Driver A's standard deviation works out to only about 1.41 minutes, while Driver B's is 14.14 minutes - ten times larger, even though both drivers average 30 minutes per delivery. When the five values you have ARE the entire population, divide the sum of squared deviations by n. When your data is only a SAMPLE meant to estimate a larger population, statisticians divide by (n - 1) instead - a correction that gives a slightly larger, less biased estimate of the population's true spread.

Note: Rule of thumb: use statistics.pstdev() (divides by n) when your dataset is the entire population you care about. Use statistics.stdev() (divides by n - 1) when your dataset is a sample used to estimate a bigger population, which is the more common situation in real analysis.
Note: For data that follows a roughly bell-shaped (normal) distribution, about 68% of values fall within one standard deviation of the mean, and about 95% fall within two standard deviations - a handy pattern known as the empirical rule.