直方图、柱状图、饼状图、散点图、箱线图
使用pandas绘图,快速获取洞见,用pandas即可
若要深入研究细节,要自定义可视化界面,就要用到matplotlib
在jupyter notebook画图,输入 % matplotlib inline 从而可以在notebook内部查看数据图
pandas画图大全
python画hist直方图www.jianshu.com- 直方图 hist
- hist函数:查看df中所有值列的直方图,直方图可以看出分布
- df.hist()
- df.hist(figsize = (8,8)); 可以用分号隐藏不需要输出的内容
- df['col'].hist();
- plot函数:df['col'].plot(kind = 'hist');
2. 柱状图 bar / 横向 barh
- df['col'].value_counts().plot(kind = 'bar');
- value_counts()是按数量多少排序的,所以为了让两个柱状图index顺序一样,可以:
- ind = df['col1'].value_counts().index
- df['col1'].value_counts()[ind].plot(kind = 'bar');
- df['col2'].value_counts()[ind].plot(kind = 'bar');
3.饼状图 pie
- df['col'].value_counts().plot(kind = 'pie', figsize = (8,8));
4.散点图 scatter
【数据可视化】Pandas画散点图_Python_探索世界,改变世界-CSDN博客blog.csdn.net- 一整个df的:pd.plotting.scatter_matrix(df, figsize=(15,15)); 该函数还会展示每个变量的直方图
- 单独的散点图:df.plot(x = 'col1', y = 'col2', kind = 'scatter');
5.箱线图 box
- df['col'].plot(kind = 'box');