Skip to content

DS 104 · Module 1

Explore Data: Distributions, Variation, and Outliers

Work through a survey and outcomes dataset while practicing center, spread, and outlier investigation to ask whether a pattern is trustworthy, not just visible.

Start Section 1
0 / 5 completed
Sync my progressJoin a session to keep progress across devices and share it with your instructor

Info

After you join, your completed lesson numbers are sent to your instructor together with your learner code, so they can see your progress. Use the codes your instructor gave you, and do not enter your name, company secrets or other personal data. Progress is kept with the rest of that session's data.

Learning objectives

  • Use EDA to generate/check questions, not to prove a preselected story
  • Compare robust and non-robust summaries; connect metrics to distribution shape
  • Describe spread; avoid interpreting a mean without variability
  • Investigate outliers before removal; document rationale and sensitivity
  • Profile distributions, missingness, group differences, and suspicious observations

The purpose of EDA

25 min

Purpose of EDA: Find Patterns and Counterexamples

Learning objective: use EDA to generate/check questions, not to prove a preselected story.

Your manager looks at a survey summary and says, "Group B clearly did worse - let's report that to the committee." Before you nod along, this is exactly where exploratory data analysis (EDA) belongs: EDA does not exist to prove a story your manager already believes. It exists to generate questions, look for evidence that supports a pattern, and just as actively look for counterexamples that would overturn it.

Search for supporting evidence

Pull only the handful of numbers that match "Group B did worse," turn them into one chart, and stop there.

Use EDA to generate and check questions

Generate a question
How large is this difference across the whole dataset? Is it consistent across subgroups, or driven by a few observations?
Look for counterexamples
Is there any stratum or subgroup where the result runs opposite to the overall pattern?
Check data quality
Could this pattern actually come from missing values, incomplete responses, or an uneven sampling stratum?
This course's dataset (load first, ask the question before concluding)
import pandas as pd

# clean: a survey + outcomes dataset, one row per observation
df = pd.read_csv("DS104_Survey_Outcomes_Clean.csv")
df.shape
df.head()
df["group"].value_counts()

# The manager's claim: Group B has a lower outcome. Look at the whole picture, not one chart
df.groupby("group")["outcome"].mean()
The same request, asked two different ways
Prove-it framingEDA framing
"Prove that Group B is worse.""How large is the mean outcome gap between Group B and Group A? Does it hold within every age_band and every sampling_stratum?"
"Find a chart that supports this conclusion.""Is there any subgroup where the result runs opposite to the overall pattern? If so, why?"
Same data, two conclusions (simulated scenario)

Overall, Group B's mean outcome really is 6 points lower than Group A's, which looks like it supports the manager's claim. But once you check by age_band, the gap turns out to be almost entirely concentrated in the youngest stratum; in the other three age bands, Group A and Group B have nearly identical means. Looking only at the overall number hides the key question of whose difference this actually is, and that is exactly the kind of counterexample EDA is meant to surface.

  • Write down the question you want to answer before you start charting or computing statistics, so the question does not quietly shift mid-analysis
  • For any "A is better/worse than B" claim, recheck it with at least one different cut (stratum, age band, completion status)
  • Actively look for a subgroup that runs opposite to the overall pattern, and note what share of the data it represents
  • Keep "what the data shows" separate from "whether the data quality supports this claim"

Warning

Data safety reminder: every exercise in this course uses the synthetic data provided. Unless authorized, never paste confidential institutional data, personal data, or other unauthorized sensitive information into an AI tool or a practice environment.

Info

Human, AI, Human: a person sets the analytical question and decides whether to accept a pattern; AI may help compute grouped statistics or draw charts; a person checks that counterexamples were actually searched for before the conclusion goes out.
Check yourself

Your manager has already decided "Group B performs worse" and asks you to build a chart that supports it. Which approach best matches the purpose of EDA?

Your manager has already decided "Group B performs worse" and asks you to build a chart that supports it. Which approach best matches the purpose of EDA?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Center and distribution

35 min

Center and Distribution: Mean, Median, Percentiles

Learning objective: compare robust and non-robust summaries; connect metrics to distribution shape.

A colleague reports, "The mean outcome is 62 - that looks fine." But if a handful of observations sit far above or below everyone else, the mean gets pulled toward those extreme values, and "that looks fine" can be wrong. The median and percentiles offer a view of the data that is not dominated by a few extreme points.

Mean

  • The sum of all values divided by the count
  • Every observation affects the result, including extreme ones
  • Most intuitive for a symmetric distribution with no extreme values

Median

  • The middle value once the data is sorted
  • An extreme value can shift it by at most one rank, never pull it far
  • Better represents a "typical" observation under skew or extreme values
Compare mean and median, then look at percentiles
summary = df["outcome"].describe(percentiles=[0.25, 0.5, 0.75])
print(summary)

mean_val = df["outcome"].mean()
median_val = df["outcome"].median()
gap = round(mean_val - median_val, 2)
# A larger gap suggests a skewed distribution, or a few extreme values pulling the mean

p10, p90 = df["outcome"].quantile([0.1, 0.9])
# 10th and 90th percentiles: 90% of observations fall within this range
What the mean-median gap tells you
SituationRelationship between mean and medianLikely interpretation
Roughly symmetric, no extreme valuesmean ≈ medianThe mean alone is usually fine for describing the center
A few observations far above the rest (right-skewed)mean > medianThe mean is pulled up by a few high values; the median better represents a typical observation
A few observations far below the rest (left-skewed)mean < medianThe mean is pulled down by a few low values; the median better represents a typical observation
Two stories behind the same 62 (simulated scenario)

Scenario one: outcome has a mean of 62 and a median of 61 - the two are close, so "that looks fine" is roughly trustworthy. Scenario two: the mean is also 62, but the median is only 48, a 14-point gap, meaning most observations actually sit below 50 and only a handful of unusually high values pulled the mean up. The same mean needs two completely different write-ups.

  • Whenever you report a "center" number for outcome, compute both the mean and median first, then decide which to lead with
  • A mean-median gap larger than roughly 5-10% of the scale is usually worth checking with a histogram
  • When communicating results, describe where most observations fall and how the few outliers deviate, rather than reporting one number alone
  • Percentiles (such as p10 and p90) show the overall shape of the data better than a single mean or median can

Warning

Reporting a single mean without looking at the shape of the distribution is one of the easiest ways to mislead a decision: two datasets with the same mean can have completely different shapes and require completely different responses.
Check yourself

In one dataset, most outcome values fall between 40 and 60, but two observations reach 300 (the rest look ordinary). When deciding which "center" number to report to a committee, what is the best approach?

In one dataset, most outcome values fall between 40 and 60, but two observations reach 300 (the rest look ordinary). When deciding which "center" number to report to a committee, what is the best approach?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Variation

35 min

Variation: Range, IQR, Standard Deviation

Learning objective: describe spread; avoid interpreting a mean without variability.

Two strata both have a mean outcome of 55, which sounds like the same situation. But if Stratum A's observations cluster tightly between 50 and 60 while Stratum B's observations spread from 10 to 100, the two datasets represent very different risks - and reporting only the mean hides that difference entirely.

Three common ways to describe spread
MetricHow it is computedSensitivity to extreme valuesBest used when
RangeMaximum minus minimumExtremely sensitive: one extreme value can change it a lotA quick check of data range; not enough on its own as a conclusion
IQR (interquartile range)75th percentile minus 25th percentileNot affected by a few extreme values; looks only at the middle 50%A first choice for skewed distributions or known outliers
Standard deviationSquare root of the average squared distance from the meanSensitive to extreme values, because distances are squaredRoughly symmetric distributions with no strong extreme values
Same mean, different spread, revealed by variation metrics
by_stratum = df.groupby("sampling_stratum")["outcome"].agg(
    mean="mean",
    std="std",
    q25=lambda s: s.quantile(0.25),
    q75=lambda s: s.quantile(0.75)
)
by_stratum["iqr"] = by_stratum["q75"] - by_stratum["q25"]
by_stratum["range"] = df.groupby("sampling_stratum")["outcome"].agg(lambda s: s.max() - s.min())
print(by_stratum)
# Means are close, but std and iqr differ a lot: the two strata spread very differently

Warning

Reporting a mean with no measure of spread hides the question of how consistent the observations behind it actually are. Decision-makers need to know whether results cluster tightly around the mean or spread out widely.
  • Pair any reported mean with at least one measure of spread (IQR or standard deviation)
  • Prefer IQR over standard deviation when the distribution may have extreme values or is clearly skewed
  • Range is extremely sensitive to a single extreme value; use it for a quick check only, never as a conclusion by itself
  • When comparing two groups, compare their spread before deciding whether a mean difference is meaningful
What picking the wrong spread metric can do (simulated scenario)

One observation in the exposure column is ten times larger than everyone else's. Using range, that single row can inflate the full range several times over, making the whole dataset look highly spread out. Using IQR instead shows that the middle 50% of observations are actually tightly clustered, with this one extreme value as the exception. Which metric you choose directly shapes your answer to "how spread out is this data, really."

  1. Plot the distribution first
    Glance at a histogram or box plot to judge whether it is clearly skewed or has extreme values.
  2. Pick a metric to match the shape
    Use standard deviation when the distribution is roughly symmetric with no extreme values; prefer IQR when it is skewed or has extreme values.
  3. Compute both as a cross-check
    Even if you only plan to report one, compute the other too and confirm the two tell a consistent story.
Check yourself

Stratum A and Stratum B both have a mean outcome of 55. Stratum A has a standard deviation of 3; Stratum B has a standard deviation of 28. Which description is most correct?

Stratum A and Stratum B both have a mean outcome of 55. Stratum A has a standard deviation of 3; Stratum B has a standard deviation of 28. Which description is most correct?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Outlier investigation

35 min

Outliers: Error, Exception, or Signal?

Learning objective: investigate outliers before removal; document rationale and sensitivity.

While checking the exposure column, you find one observation ten times larger than everyone else's. The instinct is often "that must be wrong, delete it" - but an outlier can be one of three very different things: a measurement or entry error, a rare but real exception, or a signal pointing at something important. You need to investigate which one it is before deciding what to do.

Three possible sources of an outlier and the matching action
Possible sourceHow to tellRecommended action
Error (measurement or entry)The value is physically or logically impossible, or contradicts other fields such as response_complete or weightDocument the reason, then correct or exclude it, and say so in the report
Exception (rare but real)The value is extreme but logically possible, and consistent with other fields such as age_band or groupKeep it, but flag it clearly and consider showing it separately
Signal (an important phenomenon)Several observations show a similar extreme pattern, not just one isolated caseDo not remove it as noise; investigate what is driving this group of observations
Flag candidate outliers with the IQR rule, then investigate before deciding
q1, q3 = df["exposure"].quantile([0.25, 0.75])
iqr = q3 - q1
lower, upper = q1 - 1.5 * iqr, q3 + 1.5 * iqr

flagged = df[(df["exposure"] < lower) | (df["exposure"] > upper)]
flagged[["observation_id", "exposure", "group", "response_complete", "sampling_stratum"]]
# Look at the other fields for these rows before deciding: error, exception, or signal
  1. Flag candidates with a rule
    Use the IQR rule (below Q1 - 1.5*IQR or above Q3 + 1.5*IQR) to list candidate outliers without deleting anything yet.
  2. Check the context
    Look at each candidate's other fields (response_complete, weight, age_band) to judge whether the value is logically consistent.
  3. Run a sensitivity check
    Compute the mean, median, and IQR both with and without these observations, and see whether the conclusion changes.
The same kind of extreme value, three different calls (simulated scenario)

In Stratum A, the flagged exposure value comes with a negative weight, which is logically impossible; after checking, it turns out to be an entry error that should be documented and corrected. In Stratum B, a flagged row has a normal weight and age_band, and its value simply sits at the far edge of the distribution; that is a plausible but rare exception worth keeping and flagging. In Stratum C, five flagged observations all share the same age_band and all occurred in the same sampling window; that pattern looks more like a real signal in that group, which deserves further investigation rather than being dropped.

  • A single extreme value versus a cluster of similar extreme values: the former is more likely an isolated case, the latter more likely a signal
  • Whether an extreme value logically contradicts other fields (weight, response_complete); a contradiction usually points to an error
  • Before excluding any observation, check whether the conclusion actually changes with and without it; if it does not, the exclusion matters less
  • Record both the investigation process and the conclusion in the report, not just the cleaned result after exclusion

Warning

Removing an outlier without documenting the reason quietly changes the conclusion based on intuition, and the result cannot be reproduced. Every exclusion needs a stated rationale plus a before/after sensitivity comparison.
Check yourself

You flag one extreme exposure value with the IQR rule. What should be the first step after finding it?

You flag one extreme exposure value with the IQR rule. What should be the first step after finding it?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Guided Lab

50 min

Guided Lab: Build an EDA Profile

Learning objective: with instructor guidance, profile distributions, missingness, group differences, and suspicious observations.

Info

Lab question: if you had ten minutes to brief a stakeholder on this dataset, how would a compact EDA profile - covering distribution, missingness, group differences, and suspicious observations - tell them whether the data can be trusted?
  1. Load and inspect the schema
    Load the clean data and check row count, column types, and the allowed values for group, age_band, and sampling_stratum.
  2. Check missingness and incomplete responses
    Compute the missing rate for each field and the share of observations where response_complete is false, and see whether it clusters in a specific stratum.
  3. Build a distribution summary
    Compute mean, median, IQR, and standard deviation for outcome and exposure, and plot a histogram to check the shape.
  4. Compare group differences
    Compute the mean and spread of outcome by group and age_band, and note any subgroup that looks inconsistent.
  5. Flag suspicious observations
    Use the IQR rule to flag candidate outliers, investigate one of them in context, and record your judgment.
  6. State what still needs human judgment
    List the questions this profile cannot yet answer and still need further confirmation or human judgment.
The minimum an EDA profile should include (fill in with your own output)
ItemWhat to report
Shape and schemaRow count, column types, and the allowed values of each categorical field
Missingness and completenessThe missing rate per field, and the distribution of response_complete = false
DistributionMean, median, IQR, standard deviation, and histograms for outcome and exposure
Group differencesWhether center and spread are consistent across group and age_band
Suspicious observationsFlagged candidate outliers and your judgment after investigation (error / exception / signal)
One field, two write-ups

Weak: "Stratum C has worse completeness." Strong: "In Stratum C, 34% of observations have response_complete = false, nearly four times the average of the other three strata (9%); outcome results for Stratum C should be interpreted assuming they may skew toward people who completed the survey." The second version gives a specific number, a comparison baseline, and the actual effect on the conclusion, which is what makes an EDA profile reviewable.

  • Showing only the final clean chart without saying what was excluded along the way and on what basis
  • Writing "the means differ" as "the two groups are different" without mentioning their respective spread
  • Checking only the overall data without confirming the same pattern separately by group, age_band, or sampling_stratum
  • Leaving out questions this lab still cannot answer, which makes the report look more certain than it actually is

Warning

"The code ran" is not the same as "this profile is trustworthy." Every number must be reproducible, its calculation must be explainable, and any exclusion or special handling must be documented.

Done

If AI helps compute summary statistics or draw charts, check every item yourself: whether the grouping is correct, whether the spread metric fits this distribution, and whether any flagged outlier has actually been investigated rather than dropped or ignored. AI can speed up drafting; verification and the conclusion remain a human responsibility.
Check yourself

Your EDA profile shows that Stratum C has a much higher rate of response_complete = false than other strata. What is the best way to handle this finding?

Your EDA profile shows that Stratum C has a much higher rate of response_complete = false than other strata. What is the best way to handle this finding?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

What next?