Downloads are text notes. Choose Save as PDF in your browser’s print dialog for a PDF copy.
Understand the concept
The mean adds values and divides by their count. The median is the middle value after sorting, or the average of the two central values for an even count. Large extremes can move the mean much more than the median.
A grouped summary reveals differences that an overall average can hide. Include sample sizes: a mean from two observations has a different evidential weight from a mean from two thousand. Missing values are excluded by many Pandas aggregations, so report them when relevant.
Descriptive patterns do not establish cause and effect. A relationship between study time and marks could also reflect prior preparation or other factors. Here, use a deliberately tiny sample to practise calculations rather than make claims about learners. The code uses only Python’s standard library.
Run the example
from statistics import mean, median
hours = [1, 2, 2, 3, 12]
print(f"Mean: {mean(hours):.1f}")
print(f"Median: {median(hours):.1f}")
print(f"Count: {len(hours)}")
Output / what to expect
Mean: 4.0
Median: 2.0
Count: 5
Try it yourself
Calculate the mean and median after removing 12. Explain what changed, without assuming the extreme value is an error.
View a suggested solution
from statistics import mean, median
hours = [1, 2, 2, 3]
print(mean(hours)) # 2
print(median(hours)) # 2.0
# The mean falls; the median stays the same.
# Investigate whether 12 is valid before deciding to exclude it.
Mean ke liye sab values jodo aur count se divide karo. Median sorted data ki middle value hai; even count mein beech ki do values ka average hai. Bahut badi ya chhoti values mean ko median se zyada move kar sakti hain.
Group-wise summary differences dikhati hai jo overall average mein chhup sakte hain. Sample size bhi batao: do observations ka average aur do hazaar ka average ek jaisa evidence nahi dete. Pandas ki kai aggregations missing values ko skip karti hain, toh zarurat par missing count bhi report karo.
Pattern dekhne se cause prove nahi hota. Study time aur marks ka relation prior preparation ya dusre factors se bhi ho sakta hai. Yeh chhota sample calculations practice karne ke liye hai, learners par claim karne ke liye nahi. Code standard library se chalega.
Code chalao
from statistics import mean, median
hours = [1, 2, 2, 3, 12]
print(f"Mean: {mean(hours):.1f}")
print(f"Median: {median(hours):.1f}")
print(f"Count: {len(hours)}")
Output / kya expect karein
Mean: 4.0
Median: 2.0
Count: 5
Ab khud try karo
12 hatane ke baad mean aur median nikalo. Kya change hua explain karo, lekin extreme value ko automatically error mat samjho.
Solution dekho
from statistics import mean, median
hours = [1, 2, 2, 3]
print(mean(hours)) # 2
print(median(hours)) # 2.0
# The mean falls; the median stays the same.
# Investigate whether 12 is valid before deciding to exclude it.
Run the example and attempt the exercise before marking this lesson complete.
pass the idea on
What did this make you think?
You review and publish the post yourself. Instagram uses your device’s share menu when available; otherwise copy the text and link. Facebook opens the link composer, where you add your thoughts.