Seaborn : Data Processing and Visulisation with Python (Python Exercise 27)

Data Processing and Visulisation with Python

The Data

We will be working with a famous titanic data set for these exercises. Later on in the Machine Learning course if we are able to have that course, we will revisit this data, and use it to predict survival rates of passengers. For now, we’ll just focus on the visualization of the data with seaborn.

Import seaborn and matplotlib.pyplot for later use

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

Set the style of seaborn to whitegrid

sns.set_style('whitegrid')

Load dataset titanic

Try more times if the connection is cut out. Be patient! It is not your fault.

# titanic = sns.load_dataset('titanic')
titanic = pd.read_csv("titanic.csv",index_col=0)

Check the head of the dataset

titanic.head()

Plots

Recreate the plots below using the titanic dataset. There are very few instructions since most of the plots can be done with just one or two lines of code and an instruction or a hint would basically give away the solution. Keep careful attention to the x and y labels for hints.

Do not worry about palette, cmap or color, chose anyone you like if you can not find the same with the output.

sns.jointplot(x = 'fare',y = 'age',data=titanic);

在这里插入图片描述

sns.histplot(titanic['fare'],kde=False,bins=30);
#粗细: bins

在这里插入图片描述

sns.boxplot(x='class',y='age',data=titanic,palette = 'rainbow');
# 顺序

在这里插入图片描述

sns.violinplot(x = 'class',y='age',data=titanic,palette = 'rainbow');

在这里插入图片描述

sns.countplot(x='sex',data=titanic);

在这里插入图片描述

sns.heatmap(titanic.corr(),cmap='coolwarm');
plt.title('titanic.corr()');

在这里插入图片描述

g = sns.FacetGrid(titanic,col='sex')
g.map(plt.hist,'age');

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值