Exp 9
Exp 9
---------------------------------------------------------------------------------------------------------
Group A
Assignment No: 9
-----------------------------------------------------------------------------------------------------------------
Objective of the Assignment: Students should be able to perform the data Visualization
operation using Python on any open source dataset
---------------------------------------------------------------------------------------------------------------
Prerequisite:
1. Basic of Python Programming
2. Seaborn Library, Concept of Data Visualization.
--------------------------------------------------------------------------------------------------------------
An introduction to seaborn
Seaborn is a library for making statistical graphics in Python. It builds on top of matplotlib and
integrates closely with pandas data structures.
Seaborn helps you explore and understand your data. Its plotting functions operate on dataframes
and arrays containing whole datasets and internally perform the necessary semantic mapping and
statistical aggregation to produce informative plots. Its dataset-oriented, declarative API lets you
focus on what the different elements of your plots mean, rather than on the details of how to draw
them.
# Import seaborn
import seaborn as sns
# Create a visualization
sns.relplot(
data=tips,
x="total_bill", y="tip", col="time",
hue="smoker", style="smoker", size="size",
)
A few things have happened here. Let’s go through them one by one:
# Import seaborn
import seaborn as sns
Seaborn is the only library we need to import for this simple example. By convention, it is imported
with the shorthand sns.
Behind the scenes, seaborn uses matplotlib to draw its plots. For interactive work, it’s recommended
to use a Jupyter/IPython interface in matplotlib mode, or else you’ll have to
call matplotlib.pyplot.show() when you want to see the plot.
# Create a visualization
sns.relplot(
data=tips,
x="total_bill", y="tip", col="time",
hue="smoker", style="smoker", size="size",
)
Assignment Questions
1. Write down the code to use inbuilt dataset ‘titanic’ using seaborn library. 2. Write
code to plot a box plot for distribution of age with respect to each gender along with the
information about whether they survived or not.
3. Write the observations from the box plot.