直接使用 pandas 繪圖

給 R 使用者的 Python

Daniel Chen

Instructor

Python 繪圖

  • 快速看出資料樣態
  • Python 的繪圖方式:
    • pandas
    • Seaborn
    • Matplotlib
給 R 使用者的 Python

Pandas 的 plot 方法

  • plot() 方法
  • 可用於 pandas 的 DataFrame 與 Series 物件
  • 傳入 plotkind 參數
  • 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...