Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
Data Analytics Course distributions intermediate Phase 6 — Statistics for Analytics statistics

Distributions and Outliers — What the Shape of Data Tells You

Reviewed & accurate
AI Summary

What You Will Learn

  • What a distribution is and how to visualize it
  • The difference between normal, skewed, and bimodal distributions
  • Three ways to detect outliers, including the IQR method
  • Why outliers matter — and when to remove, fix, or keep them

Why This Topic Matters

The mean and standard deviation describe a distribution with two numbers, but they assume the distribution has a "nice" shape. If the data is skewed, bimodal, or full of outliers, those two numbers are misleading. Looking at the distribution first — usually with a histogram — protects you from drawing wrong conclusions from correct calculations.

What Is a Distribution?

A distribution is the shape of how values are spread across their range. It answers: how often does each value (or range of values) occur?

The simplest way to see a distribution is a histogram, which you learned in lesson 28:

df["delivery_min"].plot(kind="hist", bins=20)

The x-axis is the value; the y-axis is how many rows fall into that bin. The shape of the bars is the distribution.

The Four Common Shapes

1. Normal (bell curve)

Symmetric, single peak in the middle, tails taper off on both sides. Mean ≈ median ≈ mode.

Examples: heights of adults, exam scores in a well-designed test, measurement errors.

Implication: mean and standard deviation describe it well. The 68-95-99.7 rule applies.

2. Right-skewed (long tail to the right)

Peak on the left, long tail stretching right. Mean > median > mode.

Examples: income, house prices, website page views, order amounts, delivery times.

Implication: mean is pulled up by the tail; use median. Log-transform may help for analysis.

3. Left-skewed (long tail to the left)

Peak on the right, long tail stretching left. Mean < median < mode.

Examples: age at retirement (most retire around 60-65, few much earlier), customer ratings (most are 4-5 stars, few are 1-2).

Implication: mean is pulled down by the tail; use median.

4. Bimodal (two peaks)

Two distinct peaks, suggesting two different populations mixed together.

Examples: delivery times during weekday vs weekend; salaries at a company with two distinct job families; customer ages for a product used by both students and retirees.

Implication: do not use mean or median blindly — segment the data first. There are two typical values, not one.

Spotting Skewness from Mean vs Median

If you do not have a histogram, comparing mean and median is a quick skewness check:

If mean >> medianIf mean ≈ medianIf mean << median
Right-skewedApproximately symmetricLeft-skewed
Use medianEither is fineUse median

The bigger the gap, the more skewed the data.

Outliers — What They Are and Why They Matter

An outlier is a value far from the rest of the data. Outliers can be:

  • Real but extreme: a ₹10-crore order from a corporate buyer. Legitimate, but it skews analysis.
  • Errors: a delivery time of 9999 minutes because the timer was not stopped. Should be removed.
  • Important signals: a sudden spike in error rates. This is the most interesting data point, not noise.

Always investigate outliers before deciding what to do. Never blindly delete them.

Three Ways to Detect Outliers

Method 1 — Visual (histogram or boxplot)

Plot the data. Points visibly separated from the main cloud are outliers. A boxplot makes this explicit by drawing "whiskers" at 1.5 × IQR; points beyond are flagged.

df["amount"].plot(kind="box")

Method 2 — Z-score (for normal distributions)

The z-score of a value is how many standard deviations it is from the mean:

z = (x - mean) / std

A common rule: |z| > 3 is an outlier. This works for normal distributions but fails for skewed data, where extreme values are normal.

Method 3 — IQR method (robust, works for any distribution)

IQR = Interquartile Range = Q3 − Q1, where Q1 is the 25th percentile and Q3 is the 75th.

Q1 = df["amount"].quantile(0.25)
Q3 = df["amount"].quantile(0.75)
IQR = Q3 - Q1

lower = Q1 - 1.5 * IQR
upper = Q3 + 1.5 * IQR

outliers = df[(df["amount"] < lower) | (df["amount"] > upper)]

The 1.5 × IQR rule is a long-standing convention. It flags roughly the most extreme 0.7% of normal data as outliers, which is reasonable for most analyses.

Worked Example — Salary Outliers

Salaries (₹ thousand): 30, 32, 35, 38, 40, 42, 45, 48, 50, 5000.

import pandas as pd
s = pd.Series([30, 32, 35, 38, 40, 42, 45, 48, 50, 5000])

Q1, Q3 = s.quantile([0.25, 0.75])
IQR = Q3 - Q1
lower = Q1 - 1.5 * IQR
upper = Q3 + 1.5 * IQR

print(Q1, Q3, IQR, lower, upper)
# 36.25  47.25  11.0  19.75  63.75

outliers = s[(s < lower) | (s > upper)]
print(outliers)
# 9    5000

The 5000 is flagged as an outlier. Without it, the mean salary is ₹40k; with it, the mean is ₹540k. The median barely moves (₹41k vs ₹40k). This is exactly why we use median for skewed data.

What to Do with Outliers

SituationAction
Clear data error (impossible value)Remove or correct
Real but extreme (bulk corporate order)Keep, but report median alongside mean
Important signal (error-rate spike)Investigate — this is the most valuable data point
Skews aggregate metrics and breaks dashboardsCap at the 99th percentile (winsorize) for that specific report
Small dataset where outlier changes the conclusionReport analysis with and without; let the reader decide
Never silently delete outliers. Always document what you removed, why, and how it changes the result. A reader of your analysis should be able to reproduce it exactly.

Common Mistakes

  1. Computing mean and SD without checking the distribution. For skewed data, they are misleading.
  2. Using z-score on skewed data. Z-scores assume normality; use IQR instead.
  3. Removing all outliers by default. Some outliers are the most important data you have.
  4. Not segmenting bimodal data. If two peaks exist, treat them as two populations.
  5. Forgetting to investigate why outliers exist. The "why" is usually more valuable than the number.

Practical Exercise (15 minutes)

Use this delivery times dataset (minutes):

[12, 14, 15, 13, 16, 15, 14, 12, 17, 15,
 14, 13, 16, 15, 14, 18, 12, 15, 99, 14]
  1. Plot a histogram with 10 bins. Describe the shape.
  2. Compute mean and median. Are they close?
  3. Use the IQR method to flag outliers.
  4. Remove the outlier(s) and recompute mean and median.
  5. How different is the picture now?

Mini Challenge

Find a public dataset (any with a numeric column — Kaggle, World Bank data, government open data). For one numeric column: plot the histogram, compute mean vs median, use IQR to find outliers, and write a one-paragraph "shape story" describing what the distribution tells you. This single paragraph is more useful than any single statistic.

Key Takeaways

  • A distribution is the shape of how values are spread. Plot a histogram before computing statistics.
  • Four common shapes: normal, right-skewed, left-skewed, bimodal.
  • If mean and median are very different, the data is skewed — use the median.
  • Detect outliers with the IQR method (robust) or z-score (for normal data).
  • Always investigate outliers before removing. Some are noise; some are the most important data you have.
Course continuity
Previously learned: Lesson 29 (mean/median/mode) and lesson 30 (variance/SD) covered individual statistics.
Today: You learned to look at the whole shape and find outliers.
Next: Lesson 32 covers the practical everyday stats: percentages, percent change, and sampling — the math of every business report.

FAQ

What is a boxplot and how do I read it?

A boxplot shows the distribution in one image: a box from Q1 to Q3 (the middle 50% of data), a line inside the box at the median, "whiskers" extending to the most extreme non-outlier values, and dots for outliers. It is the quickest way to see median, spread, and outliers at once. Make one with df["col"].plot(kind="box").

When should I log-transform skewed data?

When the data is right-skewed and spans several orders of magnitude (e.g., salaries from ₹30k to ₹3cr). Taking np.log(amount) compresses the tail and often produces a more symmetric distribution, which makes mean and SD meaningful again. Always document that you log-transformed; readers will otherwise misinterpret the numbers.

Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments