Skip to content

Instantly share code, notes, and snippets.

@luisjunco
Last active June 19, 2026 11:27
Show Gist options
  • Select an option

  • Save luisjunco/e372a523bfa19b41031d376958ea0a46 to your computer and use it in GitHub Desktop.

Select an option

Save luisjunco/e372a523bfa19b41031d376958ea0a46 to your computer and use it in GitHub Desktop.
Data Visualization - Discover Boxplots

Data Visualization - Discover: Boxplots


Iteration 1:

Research what boxplots are, what information they convey, and why they are useful.

Iteration 2:

Open a notebook and load the Titanic dataset:

import seaborn as sns
df = sns.load_dataset("titanic")

Iteration 3:

Render some boxplots, and try to answer the following questions

  • a) Is there a relationship between age and pclass (passenger class)? (e.g. did passengers in 1st class tend to be older than those in 2nd and 3rd class?)
  • b) Did passengers who survived tend to be younger or older than those who didn't?
  • c) How does ticket fare vary across passenger classes — and which class has the most outliers?

Bonus:

  • Display other types of plots using that same dataset



Solutions

Question A
plt.figure(figsize=(4, 6))
sns.boxplot(data=titanic_df, x='pclass', y='age')
plt.xlabel('Passenger Class')
plt.ylabel('Age')
plt.title('Age Distribution by Passenger Class')
plt.show()

Result:

image
Question B
plt.figure(figsize=(4, 6))
sns.boxplot(data=titanic_df, x='survived', y='age')
plt.xlabel('Survived')
plt.ylabel('Age')
plt.title('Age Distribution by Survival')
plt.show()

Result:

image
Question C
plt.figure(figsize=(4, 12))
sns.boxplot(data=titanic_df, x='pclass', y='fare')
plt.xlabel('Passenger Class')
plt.ylabel('Fare')
plt.title('Fare Distribution by Passenger Class')
plt.show()

Result:

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment