直接用 pandas 作图

面向 R 用户的 Python

Daniel Chen

Instructor

Python 作图

  • 快速展示数据模式
  • Python 作图方式:
    • pandas
    • Seaborn
    • Matplotlib
面向 R 用户的 Python

Pandas 的 plot 方法

  • plot() 方法
  • 适用于 pandas 的 DataFrame 和 Series 对象
  • 通过参数 kind 指定图形类型
  • 常见 kind
    • line:折线图(默认)
    • bar:垂直条形图
    • barh:水平条形图
  • hist:直方图
  • box:箱线图
  • kde:核密度图
  • density:同 kde
  • area:面积图
  • pie:饼图
  • scatter:散点图
  • hexbin:六边形箱图
面向 R 用户的 Python

单变量:直方图

import matplotlib.pyplot as plt
iris['sepal_length'].plot(kind='hist')
plt.show()

面向 R 用户的 Python

单变量:条形图

cts = iris['species'].value_counts()
cts.plot(kind='bar')
plt.show()

面向 R 用户的 Python

双变量:散点图

iris.plot(kind='scatter', x='Sepal.Length', y='Sepal.Width')
plt.show()

面向 R 用户的 Python

双变量:箱线图

iris.plot(kind='box')
plt.show()

面向 R 用户的 Python

双变量:箱线图

iris.boxplot(by='Species', column='Sepal.Length')
plt.show()

面向 R 用户的 Python

让我们练习一下!

面向 R 用户的 Python

Preparing Video For Download...