0% found this document useful (0 votes)
18 views

Assign9.Ipynb - Colab

The document loads and cleans a dataset on the Titanic passengers. It describes the dataset, fills in missing values, and generates a boxplot of age by gender and survival status.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Assign9.Ipynb - Colab

The document loads and cleans a dataset on the Titanic passengers. It describes the dataset, fills in missing values, and generates a boxplot of age by gender and survival status.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

4/17/24, 11:32 AM Assign9.

ipynb - Colab

#importing required library


import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

#loading dataset
data = pd.read_csv('https://raw.githubusercontent.com/dphi-official/Datasets/master/titan

data.head()

PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket F

Braund,
0 1 0 3 Mr. Owen male 22.0 1 0 A/5 21171 7.25
Harris

Cumings,
Mrs. John
Bradley
1 2 1 1 female 38.0 1 0 PC 17599 71.28
(Florence
Briggs
Th...

Heikkinen,
STON/O2.
2 3 1 3 Miss. female 26.0 0 0 7.92
3101282
Laina

Futrelle,
Mrs.
Jacques
3 4 1 1 female 35.0 1 0 113803 53.10
Heath
(Lily May
Peel)

Allen, Mr.
4 5 0 3 William male 35.0 0 0 373450 8.05
Henry

Next steps: Generate code with data


toggle_off View recommended plots

data.describe()

https://colab.research.google.com/drive/1fFnJz7K2louhKVNe-ChvVHbWHvWMlwg-#scrollTo=dMaZYkIqpMGy&printMode=true 1/4
4/17/24, 11:32 AM Assign9.ipynb - Colab

PassengerId Survived Pclass Age SibSp Parch Fa

count 891.000000 891.000000 891.000000 714.000000 891.000000 891.000000 891.0000

mean 446.000000 0.383838 2.308642 29.699118 0.523008 0.381594 32.2042

std 257.353842 0.486592 0.836071 14.526497 1.102743 0.806057 49.6934

min 1.000000 0.000000 1.000000 0.420000 0.000000 0.000000 0.0000

25% 223.500000 0.000000 2.000000 20.125000 0.000000 0.000000 7.9104

50% 446.000000 0.000000 3.000000 28.000000 0.000000 0.000000 14.4542

75% 668.500000 1.000000 3.000000 38.000000 1.000000 0.000000 31.0000

max 891.000000 1.000000 3.000000 80.000000 8.000000 6.000000 512.3292

data.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 PassengerId 891 non-null int64
1 Survived 891 non-null int64
2 Pclass 891 non-null int64
3 Name 891 non-null object
4 Sex 891 non-null object
5 Age 714 non-null float64
6 SibSp 891 non-null int64
7 Parch 891 non-null int64
8 Ticket 891 non-null object
9 Fare 891 non-null float64
10 Cabin 204 non-null object
11 Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.7+ KB

data.isnull().sum()

PassengerId 0
Survived 0
Pclass 0
Name 0
Sex 0
Age 177
SibSp 0
Parch 0
Ticket 0
Fare 0
Cabin 687
Embarked 2
dtype: int64

https://colab.research.google.com/drive/1fFnJz7K2louhKVNe-ChvVHbWHvWMlwg-#scrollTo=dMaZYkIqpMGy&printMode=true 2/4
4/17/24, 11:32 AM Assign9.ipynb - Colab

data['Age'] = data['Age'].fillna(np.mean(data['Age']))
data['Cabin'] = data['Cabin'].fillna(data['Cabin'].mode()[0])
data['Embarked'] = data['Embarked'].fillna(data['Embarked'].mode()[0])

data.isnull().sum()

PassengerId 0
Survived 0
Pclass 0
Name 0
Sex 0
Age 0
SibSp 0
Parch 0
Ticket 0
Fare 0
Cabin 0
Embarked 0
dtype: int64

sns.boxplot(x=data['Sex'], y=data['Age'], hue=data['Survived'], palette='Set2')


plt.title('Distribution of Age by Gender with Survival Information')
plt.show()

output

Start coding or generate with AI.

https://colab.research.google.com/drive/1fFnJz7K2louhKVNe-ChvVHbWHvWMlwg-#scrollTo=dMaZYkIqpMGy&printMode=true 3/4
4/17/24, 11:32 AM Assign9.ipynb - Colab

https://colab.research.google.com/drive/1fFnJz7K2louhKVNe-ChvVHbWHvWMlwg-#scrollTo=dMaZYkIqpMGy&printMode=true 4/4

You might also like