Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
📊 Unit 3 – Data Handling & NumPy  ·  Lesson 11

Statistics: Mean, Median, Mode, SD

Why statistics?

A list of 500 marks is hard to understand. Statistical measures summarise a whole data set in a few numbers: what is a typical value (central tendency — mean, median, mode) and how spread out the values are (variability — range, standard deviation). We will use the heights (cm) of 8 students:

heights →15001551160216031624165517061757
Sample data (already sorted)

Mean

Mean (average) = sum of all values ÷ number of values.

Sum = 150 + 155 + 160 + 160 + 162 + 165 + 170 + 175 = 1297; Mean = 1297 ÷ 8 = 162.125 cm.

Median

Median is the middle value after sorting. With an odd count it is the centre value; with an even count it is the average of the two middle values.

15001551160216031624165517061757
8 values → middle two are 160 and 162 → median = 161

Mode

Mode is the value that occurs most often. Here 160 appears twice, so mode = 160. Mode is the only measure that also works for non-numeric data, e.g. the most popular shoe size or favourite colour.

Frequency of each height01231501551601621651701751121111
The tallest bar is the mode

Range

Range = maximum − minimum = 175 − 150 = 25 cm. It is quick but depends only on two extreme values.

Standard deviation

Standard deviation (σ) tells how far values are, on average, from the mean. Steps: (1) find the mean, (2) subtract the mean from each value, (3) square the differences, (4) average the squares — this is the variance, (5) take the square root — this is the SD.

xx − mean(x − mean)²
2-39
4-11
4-11
4-11
500
500
724
9416
Data 2, 4, 4, 4, 5, 5, 7, 9 with mean 5: sum of squares = 32, variance = 32 ÷ 8 = 4, SD = 2
Python
data = [2, 4, 4, 4, 5, 5, 7, 9]
mean = sum(data) / len(data)
squares = [(x - mean) ** 2 for x in data]
variance = sum(squares) / len(data)
sd = variance ** 0.5
print('Mean:', mean)
print('Squared deviations:', squares)
print('Variance:', variance, '| SD:', sd)
Mean: 5.0 Squared deviations: [9.0, 1.0, 1.0, 1.0, 0.0, 0.0, 4.0, 16.0] Variance: 4.0 | SD: 2.0

All measures in Python

Method 1 — write the logic yourself (good for exams):

Python
heights = [150, 155, 160, 160, 162, 165, 170, 175]
n = len(heights)
mean = sum(heights) / n
s = sorted(heights)
if n % 2 == 0:
    median = (s[n // 2 - 1] + s[n // 2]) / 2
else:
    median = s[n // 2]
mode = max(set(heights), key=heights.count)
rng = max(heights) - min(heights)
print('Mean  :', mean)
print('Median:', median)
print('Mode  :', mode)
print('Range :', rng)
Mean : 162.125 Median: 161.0 Mode : 160 Range : 25

Method 2 — use the statistics module:

Python
import statistics as st
heights = [150, 155, 160, 160, 162, 165, 170, 175]
print(st.mean(heights), st.median(heights), st.mode(heights))
print('Population SD:', round(st.pstdev(heights), 2))
print('Variance     :', round(st.pvariance(heights), 2))
162.125 161.0 160 Population SD: 7.44 Variance : 55.36

Effect of outliers

An outlier is a value far away from the rest. It pulls the mean strongly but hardly moves the median.

Python
import statistics as st
salary = [25, 28, 30, 32, 35, 250]      # thousand rupees; one CEO salary
print('Mean  :', round(st.mean(salary), 2))
print('Median:', st.median(salary))
Mean : 66.67 Median: 31.0
One outlier: mean 66.67 but median only 310100200300E1E2E3E4E5CEO2528303235250
Median describes the typical employee better here

Two classes can have the same mean but very different spread — SD shows the difference:

Python
import statistics as st
class_a = [60, 62, 64, 66, 68]
class_b = [40, 50, 64, 78, 88]
print('Means:', st.mean(class_a), st.mean(class_b))
print('SD A :', round(st.pstdev(class_a), 2))
print('SD B :', round(st.pstdev(class_b), 2))
Means: 64 64 SD A : 2.83 SD B : 17.57

Which measure to use?

MeasureBest whenExample
MeanNumeric data without extreme valuesAverage marks of a class
MedianData has outliers or is skewedTypical salary, house prices
ModeMost common category or valueMost sold shirt size
RangeQuick idea of spreadMax − min temperature of a day
Standard deviationExact measure of spread / consistencyComparing consistency of two batsmen

Summary & practice

  • Mean = Σx ÷ n; median = middle of sorted data; mode = most frequent.
  • Range = max − min; SD = √(Σ(x − mean)² ÷ n).
  • Outliers affect the mean, not much the median.
  • Python: statistics.mean, median, mode, pstdev, pvariance.
✅ Practice

For the runs 12, 45, 45, 78, 30, 90, 45 find mean, median, mode and range by hand, then check with Python.

Answers: mean = 345 ÷ 7 ≈ 49.29, median = 45, mode = 45, range = 78.

Frequently Asked Questions

How is the median found when there is an even number of values?
Sort the values and take the average of the two middle values. For 8 values, average the 4th and 5th values.
What does a small standard deviation mean?
Values are close to the mean (consistent). A large standard deviation means values are widely spread.
Can a data set have more than one mode?
Yes. If two values appear equally often and more than others, the data is bimodal. statistics.multimode() returns all of them.
← Class 11 Informatics Practices
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicNumPy Arrays: Create, Index, Slice Your progress: 11 / 20 (55%) · Lesson 12 / 20 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free