0% found this document useful (0 votes)
6 views3 pages

Pract 9

The document outlines a data visualization task using the Titanic dataset, focusing on creating a box plot to analyze the distribution of age by gender and survival status. It includes steps for importing necessary libraries, loading the dataset, checking for missing values, and handling those missing values before plotting. The final output is a box plot that visually represents the age distribution across different genders and survival outcomes.

Uploaded by

14 Neha Chandele
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Pract 9

The document outlines a data visualization task using the Titanic dataset, focusing on creating a box plot to analyze the distribution of age by gender and survival status. It includes steps for importing necessary libraries, loading the dataset, checking for missing values, and handling those missing values before plotting. The final output is a box plot that visually represents the age distribution across different genders and survival outcomes.

Uploaded by

14 Neha Chandele
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

pract9

April 16, 2026

Data Visualization II
1. Use the inbuilt dataset ‘titanic’ as used in the above problem. Plot a box plot for
distribution of age with respect to each gender along with the information about whethe they
survived or not. (Column names : ‘sex’ and ‘age’)
2. Write observations on the inference from the above statistics.
Import Libraries
[ ]: # Import required libraries
import pandas as pd # Data handling
import seaborn as sns # Visualization
import [Link] as plt # Plotting

Load Dataset
[ ]: # Load Titanic dataset
df = sns.load_dataset('titanic')

# Display first 5 rows


print([Link]())

survived pclass sex age sibsp parch fare embarked class \


0 0 3 male 22.0 1 0 7.2500 S Third
1 1 1 female 38.0 1 0 71.2833 C First
2 1 3 female 26.0 0 0 7.9250 S Third
3 1 1 female 35.0 1 0 53.1000 S First
4 0 3 male 35.0 0 0 8.0500 S Third

who adult_male deck embark_town alive alone


0 man True NaN Southampton no False
1 woman False C Cherbourg yes False
2 woman False NaN Southampton yes True
3 woman False C Southampton yes False
4 man True NaN Southampton no True
Check Data
[ ]: # Check dataset info
print([Link]())

1
# Check for missing values
print([Link]().sum())

<class '[Link]'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 survived 891 non-null int64
1 pclass 891 non-null int64
2 sex 891 non-null object
3 age 714 non-null float64
4 sibsp 891 non-null int64
5 parch 891 non-null int64
6 fare 891 non-null float64
7 embarked 889 non-null object
8 class 891 non-null category
9 who 891 non-null object
10 adult_male 891 non-null bool
11 deck 203 non-null category
12 embark_town 889 non-null object
13 alive 891 non-null object
14 alone 891 non-null bool
dtypes: bool(2), category(2), float64(2), int64(4), object(5)
memory usage: 80.7+ KB
None
survived 0
pclass 0
sex 0
age 177
sibsp 0
parch 0
fare 0
embarked 2
class 0
who 0
adult_male 0
deck 688
embark_town 2
alive 0
alone 0
dtype: int64
Handle Missing Values (Important)

[ ]: # Remove rows where age is missing


df = [Link](subset=['age'])

2
Box Plot (Age vs Gender + Survival)

[ ]: # Boxplot of age with respect to gender and survival


[Link](x='sex', y='age', hue='survived', data=df)

[Link]("Age Distribution by Gender and Survival")


[Link]("Gender")
[Link]("Age")

[Link]()

You might also like