Skip to content
Sozhan Natarajan
← Writing

My first real blog

Loading the palmerpenguins dataset with pandas and plotting penguin counts per species with matplotlib.

· 1 min read

The palmerpenguins dataset is always useful.

from palmerpenguins import load_penguins
import pandas as pd
import numpy as np
penguins_df = load_penguins()
penguins_cleaned_df = penguins_df.dropna()
species_counts = penguins_cleaned_df['species'].value_counts()

Showing Matplotlib charts

We can display matplotlib charts directly:

import matplotlib.pyplot as plt
plot = plt.figure()
plot.set_figwidth(6)
plot.set_figheight(3)
plt.bar(species_counts.index, species_counts.values)

Bar chart of penguin counts per species after dropping rows with missing values: Adelie has the most, then Gentoo, then Chinstrap.

And save the figure for later:

plot.savefig("matplotlib_bar.png")