Describing Data
Once data is collected, the first job is to describe it: what values occur, how often, where the centre is, how widely values are spread, and whether anything looks odd. This lesson gives an overview of the toolbox; the Descriptive Statistics section then covers each tool in depth.
Describe with tables, numbers and pictures
| Approach | Examples | Good for |
|---|---|---|
| Tables | frequency tables, cross-tables | exact counts, categorical data |
| Single numbers | mean, median, standard deviation | comparing groups compactly |
| Graphs | histogram, bar chart, box plot | seeing shape, gaps and outliers |
A good description usually uses all three.
Example: reading times at a library
A library recorded how many days 30 borrowers kept a book before returning it:
import statistics
from collections import Counter
days = [14, 7, 21, 10, 14, 9, 30, 12, 14, 8, 11, 13, 15, 7, 14,
21, 10, 9, 16, 13, 12, 14, 42, 11, 10, 14, 8, 15, 13, 12]
counts = Counter(days)
for value in sorted(counts):
print(f"{value:3d} days | {'#' * counts[value]}") 7 days | ##
8 days | ##
9 days | ##
10 days | ###
11 days | ##
12 days | ###
13 days | ###
14 days | ######
15 days | ##
16 days | #
21 days | ##
30 days | #
42 days | #
The text "chart" already reveals the shape: most loans last between one and two weeks, 14 days is the most common value (the library's standard loan period), and a single loan of 42 days sits far away from the rest.
The key numbers
import statistics
days = [14, 7, 21, 10, 14, 9, 30, 12, 14, 8, 11, 13, 15, 7, 14,
21, 10, 9, 16, 13, 12, 14, 42, 11, 10, 14, 8, 15, 13, 12]
print("n =", len(days))
print("mean =", round(statistics.mean(days), 2))
print("median =", statistics.median(days))
print("mode =", statistics.mode(days))
print("range =", max(days) - min(days))
print("stdev =", round(statistics.stdev(days), 2))n = 30
mean = 13.97
median = 13.0
mode = 14
range = 35
stdev = 7.06
Together these say: a typical loan lasts about two weeks, and most loans are within roughly a week of that. The mean sits above the median because of the few very long loans.
Shape: symmetric or skewed?
The shape of a distribution matters as much as its centre.
- Symmetric: the left and right sides mirror each other; mean ≈ median.
- Right-skewed (positively skewed): a long tail of large values; mean > median. Incomes, waiting times and loan durations are typical.
- Left-skewed (negatively skewed): a long tail of small values; mean < median. Scores on an easy exam are an example.
SciPy can measure skewness as a single number: about 0 for symmetric data, positive for a right tail, negative for a left tail.
import numpy as np
from scipy import stats
rng = np.random.default_rng(5)
symmetric = rng.normal(50, 10, size=2000)
right_tail = rng.exponential(10, size=2000)
left_tail = 100 - rng.exponential(10, size=2000)
for name, x in [("symmetric", symmetric), ("right-skewed", right_tail), ("left-skewed", left_tail)]:
print(f"{name:13s} mean={x.mean():6.2f} median={np.median(x):6.2f} skew={stats.skew(x):5.2f}")symmetric mean= 50.24 median= 50.46 skew=-0.05
right-skewed mean= 9.71 median= 6.43 skew= 1.81
left-skewed mean= 89.90 median= 93.02 skew=-2.08
The pattern is clear: when the skew is positive the mean lies above the median, and when it is negative the mean lies below.
Outliers
An outlier is a value that lies unusually far from the rest. It might be an error (someone typed 420 instead of 42), or a genuine but rare event. Never delete outliers just because they are inconvenient. Investigate them, and report how you handled them. The Interquartile Range lesson shows a standard rule for flagging them.
A checklist for describing a variable
- How many values are there, and how many are missing?
- What kind of variable is it (category or number)?
- Where is the centre (mean/median, or the most common category)?
- How spread out is it?
- What is the shape: symmetric, skewed, more than one peak?
- Are there outliers or impossible values?
Test yourself
A dataset of house prices has mean 410,000 and median 325,000. What shape is it most likely to have?
- Symmetric
- Right-skewed (long tail of expensive houses)
- Left-skewed
- Uniform
scipy.stats.skew() returns −1.3 for a dataset. What does that indicate?
- A long tail on the right
- A long tail on the left
- Perfect symmetry
- An error in the data
What should you do first when you find an outlier?
- Delete it
- Replace it with the mean
- Investigate whether it is an error or a genuine rare value
- Double it