Menu
CoddyTech

Penguin Explorer

Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 60 of 60.

A field team in Antarctica measured 100 penguins of three species. penguins.csv holds one row per penguin, and a few cells are empty: pandas reads them as NaN.

Its columns: species, island, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g and sex.

Which measurement gives a species away? The team lays the species' spreads over each other, like this for bill length:

Three see-through histograms of bill length titled bill_length_mm: Adelie on the left between 34 and 43 mm, Gentoo in the middle, Chinstrap to the right, Gentoo and Chinstrap overlapping

Adelie bills stand apart. Your program draws this chart for any measurement.

challenge icon

Challenge

Hard

The program reads a column name.

  1. Read penguins.csv; print its number of penguins and how many values of the column are missing.
  2. Drop every row with a gap and print how many are kept.
  3. On one chart, loop over the species: print each one's mean of the column (1 decimal, with round) and draw its histogram with bins=8, alpha=0.5 and its name as label.
  4. Title the chart with the column, label the y axis Penguins and add a legend.

For bill_length_mm, the whole output is:

Penguins: 100
Missing bill_length_mm: 2
Kept after cleaning: 94
Adelie: 38.9
Chinstrap: 50.0
Gentoo: 46.9
Charts drawn: 1
Title: bill_length_mm
Y label: Penguins
Histograms: 3
Histogram Adelie: 8 bars, counts [4, 1, 7, 4, 7, 8, 7, 4]
Histogram Chinstrap: 8 bars, counts [1, 2, 5, 2, 5, 4, 0, 1]
Histogram Gentoo: 8 bars, counts [1, 4, 9, 7, 3, 5, 1, 2]
See-through bars: yes
Legend: Adelie, Chinstrap, Gentoo

Try it yourself

import pandas as pd
import matplotlib.pyplot as plt

species = ["Adelie", "Chinstrap", "Gentoo"]
column = input()

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Plots

Practice on your own: Online Python compiler