0% found this document useful (0 votes)
8 views6 pages

Practical 9 Code

The document contains a series of Python code snippets for data analysis and visualization using the Pandas and Seaborn libraries on the Titanic dataset. It includes various plots such as count plots, pie charts, histograms, scatter plots, bar plots, box plots, and heatmaps to explore relationships between variables like survival, age, sex, and class. The code also demonstrates data cleaning by dropping missing values before visualization.

Uploaded by

uldesoleha
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)
8 views6 pages

Practical 9 Code

The document contains a series of Python code snippets for data analysis and visualization using the Pandas and Seaborn libraries on the Titanic dataset. It includes various plots such as count plots, pie charts, histograms, scatter plots, bar plots, box plots, and heatmaps to explore relationships between variables like survival, age, sex, and class. The code also demonstrates data cleaning by dropping missing values before visualization.

Uploaded by

uldesoleha
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
You are on page 1/ 6

4/9/25, 9:36 AM dsbda09

In [1]: import pandas as pd


import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns

In [2]: from seaborn import load_dataset


data = pd.read_csv("titanic_train.csv")

In [3]: tips = load_dataset("tips")

In [4]: sns.countplot(data['Survived'])
plt.show()

In [5]: data['Sex'].value_counts().plot(kind="pie", autopct="%.2f")


plt.show()

In [6]: data = data.dropna()

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 1/6


4/9/25, 9:36 AM dsbda09

In [7]: plt.hist(data['Age'],bins=5)
plt.show()

In [8]: sns.distplot(data['Age'])
plt.show()

In [9]: sns.scatterplot(tips["total_bill"], tips["tip"])

Out[9]: <matplotlib.axes._subplots.AxesSubplot at 0x7f90d4b3fb50>

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 2/6


4/9/25, 9:36 AM dsbda09

In [10]: sns.scatterplot(tips["total_bill"], tips["tip"], hue=tips["sex"])


plt.show()

In [11]: sns.scatterplot(tips["total_bill"], tips["tip"], hue=tips["sex"], style=tip


s['smoker'])
plt.show()

In [12]: sns.barplot(data['Pclass'], data['Age'])


plt.show()

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 3/6


4/9/25, 9:36 AM dsbda09

In [13]: sns.barplot(data['Pclass'], data['Fare'], hue = data["Sex"])


plt.show()

In [14]: sns.boxplot(data['Sex'], data["Age"])

Out[14]: <matplotlib.axes._subplots.AxesSubplot at 0x7f90d4a636d0>

In [16]: sns.boxplot(data['Sex'], data["Age"], data["Survived"])


plt.show()

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 4/6


4/9/25, 9:36 AM dsbda09

In [17]: sns.distplot(data[data['Survived'] == 0]['Age'], hist=False, color="blue")


sns.distplot(data[data['Survived'] == 1]['Age'], hist=False, color="orang
e")
plt.show()

In [18]: pd.crosstab(data['Pclass'], data['Survived'])

Out[18]:
Survived 0 1

Pclass

1 52 106

2 3 12

3 5 5

In [19]: sns.heatmap(pd.crosstab(data['Pclass'], data['Survived']))

Out[19]: <matplotlib.axes._subplots.AxesSubplot at 0x7f90d47b07d0>

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 5/6


4/9/25, 9:36 AM dsbda09

In [20]: sns.clustermap(pd.crosstab(data['Parch'], data['Survived']))


plt.show()

file:///D:/PROGRAMME/CLG PRACTICALS/Sem 6/DSBDA/Sujal/Practical-9.html 6/6

You might also like