HuntExams Academy logo
Data Science Β· Chapter 16 of 43

Descriptive Statistics

Descriptive stats summarise a dataset: MEAN, MEDIAN, MODE (centre); RANGE, VARIANCE, STANDARD DEVIATION (spread); MIN, MAX, QUARTILES.

Always look at both centre and spread β€” a single number hides a lot.

Example 1 (python)
import numpy as np
x = np.array([5, 7, 8, 9, 10, 12, 100])
print(np.mean(x), np.median(x), np.std(x))
Output
21.57 9.0 32.51

One outlier pulls the mean up.

Example 2 (python)
import pandas as pd
pd.Series(x).describe()
Output
count 7
mean 21.57 ...

.describe() gives a full summary.

Key points

  • Mean = average.
  • Median = middle value (robust to outliers).
  • Std = spread.
  • Always show centre + spread together.
πŸ’‘ Note: When mean >> median, your data is skewed β€” investigate outliers before modelling.

Understanding Descriptive Statistics

Descriptive statistics compress observed data into quantities that answer specific questions: where values cluster, how much they differ, and which values mark boundaries. Imagine recording five service times in minutes. A useful summary describes both a typical wait and the variation customers experienced. These statistics describe the recorded observations; by themselves, they neither establish causes nor guarantee what future customers will experience.

The mean is the sum divided by the number of observations. Every value contributes, so a very long service time can move it substantially. The median is the middle value after sorting; with an even count, average the two middle values. It depends on position rather than the magnitude of every observation. The mode identifies the most frequent value. Multiple values can tie, and when every value occurs once, there is no uniquely informative mode.

Spread adds information that centre cannot provide. The minimum and maximum give endpoints; their difference is the range. Range is easy to understand but depends entirely on two observations. Quartiles mark positions within sorted data: Q1 is the 25th percentile, Q2 the median, and Q3 the 75th percentile. The interquartile range, IQR = Q3 βˆ’ Q1, describes the width of the middle half. Software can use different interpolation conventions, especially noticeably in small datasets.

Variance summarises squared deviations from the mean. Population variance divides their sum by n; sample variance divides by n βˆ’ 1 and requires at least two values. The latter is an unbiased estimator of population variance under independent, identically distributed sampling with finite variance. Standard deviation is the square root of variance, restoring the original measurement units. Neither calculation requires a bell-shaped distribution, but interpreting fixed standard-deviation intervals as covering particular percentages needs additional assumptions.

Choose summaries according to the question. Mean and standard deviation retain sensitivity to extremes; median and IQR are more resistant, not immune. A mean above the median can suggest a long upper tail, but does not prove a distribution’s shape. Inspect the observations or a plot. Also check units, missingness, and whether each row represents one comparable observation. Averaging numeric identifiers, for example, produces a number without a meaningful interpretation.

Practical walkthrough

Use Python 3.10 or later for the example below; only the standard-library statistics module is needed. The five invented service times are complete, finite, equally weighted observations measured in minutes. No files, external packages, or network access are required. Treat them first as the entire collection of interest, then compare the sample calculation for a possible broader population.

Start by counting and sorting. Sorting makes the median and quartiles auditable: the central observation is 4, while 14 sits well above the other values. The total is 30, so dividing by five gives a mean of 6. The repeated value 4 supplies a unique mode. A long service time therefore affects the mean without becoming the middle observation.

Next, calculate endpoints and quartiles. Explicitly choose the inclusive quantile method so the convention is visible rather than accidental. For these five sorted values, Q1 and Q3 are the second and fourth observations. Their difference is much smaller than the full range, indicating that the endpoints tell a different story from the central values.

Finally, print both variance conventions with labels. Format floating-point results to two decimal places for stable, readable output; formatting changes the display, not the stored measurements. In pandas, a numeric Series.describe() supplies count, mean, sample standard deviation, endpoints, and quartiles, but not every statistic shown here. Its count excludes missing values. The pandas guide separates descriptive operations from missing-data handling for good reason: inspect both. If these summaries later support model preprocessing, estimate imputation or scaling parameters from training data only.

Worked example

from statistics import mean, median, multimode, quantiles
from statistics import pvariance, pstdev, variance, stdev

minutes = [2, 4, 4, 6, 14]
q1, q2, q3 = quantiles(minutes, n=4, method="inclusive")

print(f"Count: {len(minutes)}")
print(f"Mean: {mean(minutes):.2f} min")
print(f"Median: {median(minutes):.2f} min")
print(f"Modes: {multimode(minutes)} min")
print(f"Min: {min(minutes)} min; max: {max(minutes)} min")
print(f"Range: {max(minutes) - min(minutes)} min")
print(f"Q1: {q1:.2f} min; Q3: {q3:.2f} min; IQR: {q3 - q1:.2f} min")
print(f"Population variance: {pvariance(minutes):.2f} min^2")
print(f"Population standard deviation: {pstdev(minutes):.2f} min")
print(f"Sample variance: {variance(minutes):.2f} min^2")
print(f"Sample standard deviation: {stdev(minutes):.2f} min")

Expected output

Count: 5
Mean: 6.00 min
Median: 4.00 min
Modes: [4] min
Min: 2 min; max: 14 min
Range: 12 min
Q1: 4.00 min; Q3: 6.00 min; IQR: 2.00 min
Population variance: 17.60 min^2
Population standard deviation: 4.20 min
Sample variance: 22.00 min^2
Sample standard deviation: 4.69 min

Relative to the mean of 6, the deviations are βˆ’4, βˆ’2, βˆ’2, 0, and 8. Their squares sum to 88. Dividing by five gives population variance 17.60; dividing by four gives sample variance 22.00. Taking square roots produces the displayed standard deviations. The median of 4 and IQR of 2 describe the central observations, while the range of 12 exposes the distance between extremes. The 14-minute service contributes 64 of the 88 squared-deviation units. That influence is mathematical, not evidence of a recording error. Keep the observation unless a justified data-quality or scope rule says otherwise.

Common mistakes and how to avoid them

  • Comparing standard deviations without checking their denominators.

    Label the convention explicitly. NumPy's std defaults to division by n; pandas Series.std defaults to n βˆ’ 1. Use matching ddof settings when comparing results.

  • Replacing missing measurements with zero before summarising.

    Zero is an observed quantity, not an absence. Report missing and observed counts separately, then document any exclusion or imputation rule and its limitations.

  • Deleting a large value because the mean exceeds the median.

    Check measurement units, collection records, and the observation's relevance. A genuine extreme belongs in the dataset; consider reporting resistant summaries alongside mean and standard deviation.

  • Reporting variance as though it had the original units.

    Label variance in squared units, here minutes squared. Use standard deviation when you need a spread measure expressed directly in minutes.

Review questions

If 14 became 24, what would happen to the mean and median?

The total would increase by 10, raising the mean by 10/5 = 2 to 8. The middle observation would remain 4, so the median would not change.

Why report IQR as well as range?

Range describes the endpoints, whereas IQR describes central spread. Here, a range of 12 and IQR of 2 show that the middle observations are much closer together.

Does dividing by n βˆ’ 1 make an unrepresentative sample representative?

No. It adjusts the variance estimator under sampling assumptions; it cannot repair selection bias, missing groups, inconsistent measurements, or inappropriate weighting.

Can these statistics explain why one service took longer?

No. They describe differences but do not identify causes. Investigating the longer service requires contextual information, and causal conclusions require a suitable study design and assumptions.

Further reading

πŸ“ Quick Quiz

1. The middle value of sorted data is the:

2. Standard deviation measures:

3. Which is most robust to outliers?