继续前面的练习,之前的文章参考:
- pandas实例-了解你的数据-Chipotle
- pandas实例-筛选与排序-Chipotle
- pandas实例-数据可视化-Chipotle
- pandas实例-了解你的数据-Occupation
- pandas实例-筛选与过滤-Euro 12
- pandas实例-筛选与过滤-Fictional Army
- pandas实例-聚合-Alcohol Consumption
- pandas实例-聚合-Occupation
- pandas实例-聚合-Regiment
- pandas实例-Apply-Student Alcohol Consumption
- pandas实例-Apply-Crime Rates
- pandas实例-Merge-MPG Cars
- pandas实例-Merge-Fictitious Names
- pandas实例-merge-House Market
- pandas实例-Stats-US_Baby_Names
- pandas实例-Stats-Wind Statistics
- pandas实例-Visualization-Titanic_Desaster
- pandas实例-Visualization-Scores
- pandas实例-Visualization-Online Retail
这是可视化的最后1篇了,大概看了下,这一篇主要关于seaborn
我们的数据集,这次是seaborn中内置的
tips = sns.load_dataset("tips")
本来直接加载就行,但是,我这里突然报错了,一个网络问题,难道数据集还得vpn,最近vpn不好用,算了,使用本地的文件吧
tips = pd.read_csv(data_path)

1. Delete the Unnamed 0 column
删除无效列
tips.drop(columns=['Unnamed: 0'] , inplace=True)

2. Plot the total_bill column histogram
画一个直方图,可以参考:
sns.distplot(tips['total_bill'])

这里,顺道学了俩函数,哈哈哈
一个是axes设置属性的,一个是删除坐标轴的
ax = sns.distplot(tips['total_bill'])
ax.set(xlabel='hi,total_bill' , ylabel='hi,y' , title='hi,title')
sns.despine()

3. Create a scatter plot presenting the relationship between total_bill and tip
这个我本来以为就是画个散点图就行,但是看作者的意思,不是,用了个函数,我先去看看是啥
通常来说,画个散点图,可以使用:
sns.relplot(x='total_bill' , y='tip' , data=tips)

但是,作者使用了jointplot
sns.jointplot(x='total_bill' , y='tip' , data=tips)

这个看上去是个组合图,一个散点图+两个直方图
也就是展示了2个变量的关系,和每个变量自身的分布情况
4. Create one image with the relationship of total_bill, tip and size.
这个题,又学习到了反正,另一个函数
sns.pairplot(tips)

这个函数有点儿意思,是把数据中所有的数值型的变量都展示出来,显示它们各个之间的关系
5. Present the relationship between days and total_bill value
同样是一个函数的使用,参考:
sns.stripplot(x='day' , y='total_bill' , data=tips)

通常绘制散点图,需要两个变量都是数值,但是这个函数,可以实现针对一个分类变量,这个还是很有用的
6. Create a scatter plot with the day as the y-axis and tip as the x-axis, differ the dots by sex
依然可以使用上面那个函数
sns.stripplot(x='tip' , y='day' , data=tips , hue='sex')

好了,这一篇基本都是和seaborn有关,算是普及介绍吧,后面还有俩函数,也很常用,我后面会单独介绍,好了,收工。
网友评论