Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 38 ยท Projects and Practice

Project: Exploring a Penguin-Style Dataset

Walk through a complete exploratory analysis with seaborn: inspect data, plot distributions, compare groups, find relationships and write down what you learned.

Exploratory data analysis (EDA) is what you do before any model: you look at the data until you understand it. This project goes through a full EDA with seaborn on a synthetic dataset of 300 penguins from three islands. The data is generated in the lesson so everything is reproducible, and the numbers are made up, but the workflow is the one you use on real files.

You will follow five steps: inspect, clean, look at distributions, compare groups, and look for relationships. At each step you ask a question, draw a chart that answers it, and write down the answer.

The EDA loop

Inspect Shape, types, missing values.
Distributions What does each column look like?
Compare groups Do species differ?
Relationships Which columns move together?

Every chart answers one written question.

1 / 2

Step 1: build and inspect the data

Real data arrives with gaps. We add a few missing values on purpose so you can practise handling them.

Python Create the dataset and inspect it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

What to write down: 300 rows, 8 missing bill lengths, 5 missing sexes, masses between about 2,700 and 5,800 grams. Nothing impossible (no negative masses), so no cleaning of outliers is needed. We will drop rows with missing values only for the plots that need that column; seaborn skips NaN automatically.

Step 2: distributions

Question: what does body mass look like, and does it differ by species?

Python Distribution of mass overall and by species

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Write down: the overall distribution is bimodal. Splitting by species explains it: Gentoo is about 1.3 kg heavier, while Adelie and Chinstrap overlap almost completely. Lesson: an odd shape in a combined distribution is often a hidden grouping variable.

Step 3: compare groups

Question: how do species compare on every measurement, and is the pattern the same for both sexes?

Python Group comparisons with a long-form table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

melt turns four columns into one value column plus a measure label, which is what col="measure" needs. sharey=False is essential here because the measures have different units.

Write down: Gentoo has the longest flippers and heaviest mass but the shallowest bills; Chinstrap has the longest bills. In every species and every measure, males are larger than females. Species separate best on flipper length and bill depth.

Step 4: relationships

Question: which measurements move together, and does the relationship change by species? Draw a pair plot and a correlation heatmap:

Python Pair plot and correlation heatmap

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Compare the two heatmaps. Pooled over all penguins, bill depth and flipper length are negatively correlated (Gentoo have shallow bills and long flippers), but inside one species they are positively correlated (bigger birds have bigger everything). This reversal is Simpson's paradox. A pooled line would give the wrong answer about how bodies scale; always check a relationship within groups. The tool for it was in regression plots: lmplot(hue=...).

Step 5: write the findings

An EDA ends with words. A summary for this dataset:

  1. Data is clean; 8 missing bill lengths and 5 missing sexes.
  2. Body mass is bimodal because of Gentoo, which weighs about 1.3 kg more than the others.
  3. Adelie and Chinstrap differ in bill length, not in mass.
  4. Males are larger in all species.
  5. Pooled correlations mislead; within species all size measures rise together.
  6. Next steps: test the species differences formally, and check island effects for Adelie.

Your turn

Extend the project:

  • Add island and show the species-by-island table with pd.crosstab and a countplot.
  • Draw a clustermap of the four measures to see which cluster together (clustermaps).
  • Make a ridgeline of mass by species (ridgeline plots).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A histogram of all values has two humps. What should you suspect?

    Mixing groups with different centres produces several humps. Split by candidate groups to check.
  2. 2. Why do we melt columns before catplot with col='measure'?

    Figure-level functions facet on a column, so the measures must become values of one column.
  3. 3. What is Simpson's paradox?

    Pooling groups with different levels can create a trend opposite to the within-group trend.
  4. 4. Why sharey=False when faceting different measures?

    Bill depth in mm and mass in grams cannot share an axis.

Summary

  • Work in a loop: ask a question, draw one chart, write down the answer.
  • Check missing values and summary statistics before plotting.
  • Split distributions and relationships by group to avoid misleading pooled results.
  • melt + catplot(col=...) compares many measures at once.

Next: Project: Sales Dashboard