Beginner: data foundations · Statistics made simple · topic 6 of 62 · 30 min
Types of data, and the centre: mean, median, mode
Explanation
Why statistics?
A column of 10,000 numbers means nothing to a human. Statistics is a set of tools that squeezes a column into a few honest numbers: what is typical, how spread out the values are, and what is unusual. Descriptive statistics, the subject of this module, describes the data you have. Module 3 adds inferential statistics, which uses a sample to make careful claims about a bigger group.
Kinds of data
Before choosing a summary, know what kind of data a column holds. The kind decides which summaries make sense.
| Kind | Meaning | Examples |
|---|---|---|
| Numeric, discrete | Counts: whole numbers you get by counting | Children in a family, orders per day, goals scored |
| Numeric, continuous | Measurements that can take any value in a range | Height, rainfall in mm, delivery time, salary |
| Categorical, nominal | Labels with no natural order | City, blood group, payment method (UPI, card, cash) |
| Categorical, ordinal | Labels with an order, but the gaps are not equal | T-shirt size S/M/L, rating poor/good/excellent, class 8/9/10 |
Population and sample
The population is the whole group you care about, such as all voters in India. A sample is the part you actually measured, such as 2,000 voters in a survey. Usually you cannot measure everyone, so you summarise a sample and use it to estimate the population. Keep the difference in mind: it matters for the spread in the next topic.
The mean
The mean (the ordinary average) is the total divided by how many values there are. In words: add everything up, then share it out equally. It uses every value, which is its strength and its weakness, because one extreme value pulls it a long way.
The median
The median is the middle value after sorting. With an odd number of values it is the one in the middle; with an even number it is the average of the two middle values. Half the data is below it and half above, and extreme values barely move it.
salaries = [25, 28, 30, 32, 35, 40, 400] # monthly salary, ₹ thousand, in a small company
mean = sum(salaries) / len(salaries)
print(round(mean, 2)) # 84.29
s = sorted(salaries)
print(s[len(s) // 2]) # 32def median(values):
s = sorted(values)
n = len(s)
mid = n // 2
if n % 2 == 1:
return s[mid]
return (s[mid - 1] + s[mid]) / 2
print(median([7, 1, 5])) # 5
print(median([40, 10, 30, 20])) # 25.0Skew and outliers
An outlier is a value far away from the rest. A distribution is skewed when one side has a long tail. Salaries, house prices and delivery times are usually right-skewed: most values are modest and a few are very large. In right-skewed data the mean is bigger than the median. That is why reports on income usually give the median.
The mode
The mode is the value that appears most often. It is the only one of the three that works for nominal data: the most common payment method, the most sold shoe size. A column can have two modes (bimodal) or more. Python's statistics.mode returns the first one it meets in the data, and statistics.multimode returns all of them as a list.
import statistics
sizes = [8, 9, 8, 10, 7, 8, 9]
print(statistics.mean(sizes), statistics.median(sizes), statistics.mode(sizes)) # 8.428571428571429 8 8
print(statistics.multimode(["UPI", "cash", "UPI", "cash", "card"])) # ['UPI', 'cash']Which one to use
- Mean: numbers without extreme values, or when the total matters (average bill, average marks).
- Median: skewed numbers or data with outliers (salaries, house prices, delivery times).
- Mode: categories, or the most common exact value (popular size, top payment method).
Common mistakes
- Reporting only the mean of skewed data. Fix: report the median too, and say why they differ.
- Forgetting to sort before taking the middle value. Fix: always use sorted(values) first.
- Averaging labels such as PIN codes or ratings coded 1–5 without thinking. Fix: check the kind of data first; for ordinal ratings the median or the share of each rating is often clearer.
- Treating 0 as missing, or missing as 0. Fix: remove or mark missing values before averaging.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Types of data, and the centre: mean, median, mode · 1/7
In this lesson you will learn the kinds of data, and the three ways to describe a typical value: the mean, the median and the mode.
Prefer a video by a teacher? Find free videos on “mean median mode types of data statistics for beginners” on YouTube ↗
In real life: Salary reports and job portals
Salary surveys and job portals usually show a median salary for a role, not the mean, because a few very high packages would make the mean misleading. When a college says "average package ₹12 LPA", a careful reader asks for the median too: a handful of large international offers can lift the average far above what most students receive.
packages = [4.5, 5, 5, 6, 6.5, 7, 8, 45] # ₹ LPA, made-up placement offers
mean = sum(packages) / len(packages)
s = sorted(packages)
median = (s[3] + s[4]) / 2
print(round(mean, 2), median)Practice (0/3 done)
Without the statistics module, write mean_of(values) that returns the mean of a list of numbers rounded to 2 decimal places. Return None for an empty list.
Without the statistics module, write median_of(values). Sort a copy of the values (do not change the input list). For an odd count return the middle value; for an even count return the average of the two middle values. Return None for an empty list.
Without the statistics module, write mode_of(values) that returns the most common value. If several values tie for the highest count, return the SMALLEST of them. Return None for an empty list.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Spread: range, variance and standard deviationStatistics made simple · same module
- Percentiles, quartiles and outliersStatistics made simple · same module
- The normal distribution and z-scoresStatistics made simple · same module
- CSV files and simple statisticsPython Programming · Working with data
- Merge sort and quick sortData Structures and Algorithms (DSA) for interviews · Sorting and searching
- Heap patterns: top-k and streamsData Structures and Algorithms (DSA) for interviews · Heaps and greedy algorithms
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which of these is ordinal data?
Answer: Customer rating: poor, good, excellent
The ratings have a natural order, but the gaps between them are not measured, so they are ordinal.
Monthly salaries in a team are mostly ₹30–40 thousand, plus one of ₹5 lakh. Which summary best describes a typical salary?
Answer: Median
The median ignores how far out the one huge salary is; the mean is pulled up by it.
What is the median of [12, 3, 9, 6]?
Answer: 7.5
Sorted: 3, 6, 9, 12. The two middle values are 6 and 9, and their average is 7.5.
Which summary can you use for the column "payment method" (UPI, card, cash)?
Answer: Mode
Nominal labels have no order and no arithmetic, so only the most common value (the mode) makes sense.
In right-skewed data such as house prices, how do the mean and median usually compare?
Answer: The mean is bigger
The long tail of very expensive houses pulls the mean above the median.
marks = [40, 50, 90]. What is statistics.median(marks)?Related
Answer: 50
Sorted, the middle value of 40, 50, 90 is 50. The mean would be 60.
What is statistics.median([10, 20, 1000])?Related
Answer: 20
The median is the middle value after sorting: 20. One huge value does not pull it up.
You surveyed 50 of a company's 5,000 employees and want to estimate the spread of all salaries. Which formula fits?Related
Answer: Sample SD, dividing by n − 1
The 50 people are a sample used to estimate the population, so Bessel's correction (n − 1) applies.
Why is the IQR often preferred to the range for skewed data?Related
Answer: It uses only the middle 50% of values, so extreme values do not distort it
The IQR ignores the top and bottom quarters, where outliers live.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Statistics made simple” before its exam: Spread: range, variance and standard deviation, Percentiles, quartiles and outliers, The normal distribution and z-scores, Correlation: how two things move together.
- Module 2 exam: Statistics made simple · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Probability and inference. 62 topics left in the course before the final exam.