Exploratory data analysis (EDA) is the first look at a dataset before any modelling or reporting: what is in it, what is missing and which patterns stand out. The Titanic passenger dataset is the classic beginner EDA project because it is small (891 rows in the common Kaggle training file), real and has an easy question: who survived?
What Is EDA, Step by Step?
- Load the data and check its size and column types.
- Find missing values and decide how to handle them.
- Look at one variable at a time (distributions).
- Compare variables (for example survival by sex and class).
- Create useful new features.
- Write down findings and open questions.
Step 1: Load the Titanic Dataset
Download train.csv from the Kaggle “Titanic – Machine Learning from Disaster” competition, or load the copy bundled with seaborn.
import pandas as pd df = pd.read_csv("train.csv") # Kaggle file: 891 rows, 12 columns # or: import seaborn as sns; df = sns.load_dataset("titanic") (lowercase column names) print(df.shape) df.info() print(df.describe())
Key columns: Survived (0/1), Pclass (1st, 2nd, 3rd class), Sex, Age, SibSp and Parch (family aboard), Fare, Cabin and Embarked (port).
Step 2: Missing Values
print(df.isna().sum().sort_values(ascending=False).head(4)) # Cabin 687 # Age 177 # Embarked 2
Cabin is missing for most passengers, so it is better turned into a yes/no “has cabin” flag than filled. Age is missing for about 20% of rows; filling it with the median age per passenger class and sex is a common, explainable choice. Embarked has only two gaps, which can take the most common port.
df["HasCabin"] = df["Cabin"].notna().astype(int) df["Age"] = df["Age"].fillna(df.groupby(["Pclass", "Sex"])["Age"].transform("median")) df["Embarked"] = df["Embarked"].fillna(df["Embarked"].mode()[0])
Step 3: Survival Rates
print(df["Survived"].mean()) # about 0.38 print(df.groupby("Sex")["Survived"].mean()) # female ~0.74, male ~0.19 print(df.groupby("Pclass")["Survived"].mean()) # 1st ~0.63, 2nd ~0.47, 3rd ~0.24 print(pd.crosstab(df["Pclass"], df["Sex"], values=df["Survived"], aggfunc="mean").round(2))
| Group | Approx. survival rate |
|---|---|
| All passengers | 38% |
| Women | 74% |
| Men | 19% |
| 1st class | 63% |
| 2nd class | 47% |
| 3rd class | 24% |
Step 4: Charts With pandas
import matplotlib.pyplot as plt df["Age"].plot(kind="hist", bins=30, title="Age distribution") plt.show() df.groupby("Pclass")["Survived"].mean().plot(kind="bar", title="Survival rate by class") plt.show() df.boxplot(column="Fare", by="Pclass") plt.show()
The fare box plot shows a few very high first-class fares. They are real values, not errors, which is an important EDA lesson: check outliers before removing them.
Step 5: Feature Engineering
df["FamilySize"] = df["SibSp"] + df["Parch"] + 1 df["IsAlone"] = (df["FamilySize"] == 1).astype(int) df["Title"] = df["Name"].str.extract(r",\s*([^\.]+)\.") # Mr, Mrs, Miss, Master... df["AgeGroup"] = pd.cut(df["Age"], bins=[0, 12, 18, 35, 60, 80], labels=["Child", "Teen", "Young adult", "Adult", "Senior"]) print(df.groupby("IsAlone")["Survived"].mean())
Step 6: Write Down the Findings
- Sex was the strongest single factor: women survived at roughly four times the rate of men.
- Class mattered: first-class passengers survived at about 2.5 times the rate of third class.
- Passengers travelling alone survived less often than those in small families.
- Cabin is mostly missing; having a recorded cabin is linked with higher class.
Good EDA ends with questions too: was the “women and children first” rule applied the same way in every class? That is how EDA leads to deeper analysis.
Doing EDA With Claude AI
You can ask Claude to run the same steps on any file: “Profile this dataset, list missing values with a suggested fix for each, and show survival rate by sex and class with the pandas code.” More prompts are in Claude prompts for data analysis. The course Claude AI for Data Analysis & Business Intelligence has a dedicated EDA section on the Titanic dataset, a data visualization section with pandas and a hands-on EDA section with ChatGPT, so you can compare doing it by hand and with AI.
Data analysis with AI: Claude AI for data analysis · Claude prompts for data analysis · pandas for data analysis · data analyst interview questions · AI data analyst course in India · business intelligence course · data analyst roadmap 2026 · ETL testing vs data analyst · data analytics for working professionals · AI tools for data analysis
Frequently Asked Questions
What is EDA in Python?
Exploratory data analysis in Python means using libraries such as pandas and matplotlib to inspect a dataset’s size, types, missing values, distributions and relationships before deeper analysis.
Why is the Titanic dataset used for EDA?
It is small, real, has missing values and a clear question (who survived), so beginners can practise every EDA step in under an hour.
Where can I download the Titanic dataset CSV?
From the Kaggle “Titanic – Machine Learning from Disaster” competition (train.csv), or load it with seaborn.load_dataset("titanic").
What are the main findings of Titanic EDA?
Women survived far more often than men (about 74% vs 19%), and first-class passengers survived more than third class (about 63% vs 24%).
Asim Noaman Lodhi
Certified Google Partner · QA Consultant · 12+ Years IT
QA consultant specializing in ETL testing and data quality. Trained 913+ students to transition into data testing roles through hands-on, real-world instruction.