Two delivery partners both average 30 minutes per delivery. One is almost always between 28 and 32 minutes; the other swings between 15 and 50. The average does not show this difference. Spread does, and standard deviation is the most common measure of spread.
Variance in four steps
Take delivery times of 26, 28, 30, 32 and 34 minutes.
- Find the mean: 30.
- Subtract the mean from each value: −4, −2, 0, 2, 4.
- Square each difference: 16, 4, 0, 4, 16.
- Average the squares: 40 ÷ 5 = 8. That is the variance.
Squaring makes all differences positive and gives more weight to large deviations.
Standard deviation
Variance is in squared units (minutes squared), which is hard to interpret. Take the square root: √8 ≈ 2.8 minutes. That is the standard deviation, in the original units: values typically sit a few minutes from the mean.
import numpy as np
times = np.array([26, 28, 30, 32, 34])
times.var() # population variance, divides by n
times.std() # population standard deviation
times.std(ddof=1) # sample standard deviation, divides by n - 1Population vs sample
- If your data is the whole population you care about, divide by n.
- If it is a sample used to estimate a larger population, divide by n − 1. This small correction avoids systematically underestimating spread.
Defaults differ: NumPy uses n (ddof=0) while pandas .std() uses n − 1. In Excel, STDEV.P is population and STDEV.S is sample. Knowing this explains why two tools sometimes give slightly different answers.
Interpreting standard deviation
- Small: values cluster tightly around the mean, the process is consistent.
- Large: values are widely scattered, outcomes are less predictable.
For roughly bell-shaped data, about two-thirds of values fall within one standard deviation of the mean and about 95% within two. For skewed data, this rule does not hold well, and percentiles are more informative.
Comparing spread across different scales
Is a standard deviation of ₹50 large? It depends on the mean. The coefficient of variation (standard deviation ÷ mean) compares relative spread: ₹50 on an average of ₹100 is very variable; ₹50 on ₹10,000 is very stable.
How analysts use it
- Consistency: compare reliability of suppliers, delivery partners or machines.
- Outlier detection: flag values more than a few standard deviations from the mean (z-scores).
- Control limits: in operations, track whether a process stays within expected bounds.
- Risk: in finance, volatility of returns is a standard deviation.
- Scaling for ML: standardising features divides by the standard deviation.
Its weakness
Because differences are squared, a single extreme value inflates the standard deviation a lot. For skewed data with outliers, the interquartile range (75th percentile minus 25th) is a more robust spread measure.
Practise
Calculate both kinds in our NumPy statistics set, and compare spread visually with box plots in the comparing categories set.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: