Skip to content

Exploratory Data Analysis (EDA) on Titanic

Perform EDA on the Titanic dataset and produce:

  • Data quality findings (missing values, types)
  • A handful of clear plots
  • Insights about survival patterns

Every EDA project follows the same rhythm: load the raw file, fix the messy parts, ask simple questions of the clean data, draw a picture, then write down what you saw.

diagram Titanic EDA pipeline mermaid
From raw CSV to survival insights, one stage at a time.

Common sources:

  • Kaggle: Titanic - Machine Learning from Disaster

Typical columns:

  • Survived, Pclass, Sex, Age, SibSp, Parch, Fare, Embarked
Load Titanic CSV
import pandas as pd
 
df = pd.read_csv("data/titanic.csv")
print(df.shape)
print(df.head())
Info + missing
print(df.info())
 
missing = (df.isna().mean() * 100).sort_values(ascending=False)
print(missing)

Focus on missing in:

  • Age
  • Cabin
  • Embarked
Embarked fill
if "Embarked" in df.columns:
    df["Embarked"] = df["Embarked"].fillna(df["Embarked"].mode().iloc[0])
Cabin flag
if "Cabin" in df.columns:
    df["has_cabin"] = df["Cabin"].notna()
Survival count
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(6, 4))
sns.countplot(data=df, x="Survived")
plt.title("Survival counts")
plt.tight_layout()
plt.show()
Age distribution
import seaborn as sns
import matplotlib.pyplot as plt
 
if "Age" in df.columns:
    plt.figure(figsize=(7, 4))
    sns.histplot(df["Age"].dropna(), bins=30, kde=True)
    plt.title("Age distribution")
    plt.tight_layout()
    plt.show()
Survival by sex
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
sns.barplot(data=df, x="Sex", y="Survived")
plt.title("Survival rate by sex")
plt.tight_layout()
plt.show()
Survival by class
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
sns.barplot(data=df, x="Pclass", y="Survived")
plt.title("Survival rate by class")
plt.tight_layout()
plt.show()
Fare vs survival
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=df, x="Survived", y="Fare")
plt.title("Fare vs survival")
plt.tight_layout()
plt.show()

A pivot_table collapses “survival by sex” and “survival by class” into a single matrix — the same trick McKinney uses to get mean movie ratings by gender in one line instead of several separate groupby calls.

Survival matrix
matrix = df.pivot_table("Survived", index="Pclass", columns="Sex", aggfunc="mean")
print(matrix)
sketch Survival rate by class and sex p5.js
Taller amber bars mean a higher survival rate for that class/sex group.

Write 5–10 bullet insights such as:

  • Survival rate is higher for females.
  • Higher class passengers survived more.
  • Passengers who paid higher fare tended to survive more.
  • Missingness is high in Cabin; treat as a feature (“has_cabin”).

Save a cleaned dataset version:

Save output
df.to_csv("output/titanic_cleaned.csv", index=False)

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading