ds9
ds9
[15]: 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
[23]: titanic.info()
<class 'pandas.core.frame.DataFrame'>
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
1
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
[25]: titanic.describe()
2
[33]: titanic['survived'] = titanic['survived'].map({0: 'No', 1: 'Yes'})
plt.figure(figsize=(8, 6))
sns.countplot(data=titanic, x='pclass', hue='survived')
plt.title('Survival Count by Passenger Class')
plt.xlabel('Passenger Class')
plt.ylabel('Count')
plt.legend(title='Survived')
plt.show()
3
[37]: plt.figure(figsize=(10, 6))
sns.histplot(data=titanic, x='age', hue='survived', bins=30, kde=True,␣
↪multiple='stack')
4
[39]: plt.figure(figsize=(12, 6))
sns.heatmap(titanic.isnull(), cbar=False, cmap='viridis')
plt.title('Missing Values in Titanic Dataset')
plt.show()
5
[43]: titanic['survived'] = titanic['survived'].map({'No': 0, 'Yes': 1})
numeric_data = titanic.select_dtypes(include='number')
/home/admin1/anaconda3/lib/python3.9/site-packages/seaborn/matrix.py:260:
FutureWarning: Format strings passed to MaskedConstant are ignored, but in
future may error or produce different behavior
annotation = ("{:" + self.fmt + "}").format(val)
6
[50]: plt.scatter(titanic["age"],titanic["fare"])
numeric_clean = numeric_cols.dropna()
sns.pairplot(numeric_clean)
plt.suptitle('Pairwise Relationships in Titanic Numeric Data', y=1.02)
plt.show()
7
[60]: sns.pairplot(titanic,hue="sex")
8
[64]: sns.boxplot(titanic["fare"])
9
[74]: sns.displot(titanic["fare"])
10
[76]: plt.hist(titanic["fare"])
[76]: (array([732., 106., 31., 2., 11., 6., 0., 0., 0., 3.]),
array([ 0. , 51.23292, 102.46584, 153.69876, 204.93168, 256.1646 ,
307.39752, 358.63044, 409.86336, 461.09628, 512.3292 ]),
<BarContainer object of 10 artists>)
11
[ ]: sns.jointplot(titan)
12