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:
Adelie bills stand apart. Your program draws this chart for any measurement.
Challenge
HardThe program reads a column name.
- Read
penguins.csv; print its number of penguins and how many values of the column are missing. - Drop every row with a gap and print how many are kept.
- On one chart, loop over the species: print each one's mean of the column (1 decimal, with
round) and draw its histogram withbins=8,alpha=0.5and its name as label. - Title the chart with the column, label the y axis
Penguinsand 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, GentooTry it yourself
import pandas as pd
import matplotlib.pyplot as plt
species = ["Adelie", "Chinstrap", "Gentoo"]
column = input()
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Data and Plots
2NumPy Arrays
Creating ArraysShape and SizeRanges of NumbersIndexing and SlicingRecap: Temperature GridPractice on your own: Online Python compiler