開始使用免費開始

建立點狀圖(point plot)

要做出有用的視覺化,有時需要多次嘗試。現在你被要求建立一個圖表,顯示在不同飯店星等("Hotel stars")下,評論者先前撰寫過的評論數("Nr. reviews")。由於評論數是數值型資料,你決定使用點狀圖來呈現各類別的平均值。

本練習屬於課程

在 Python 中處理類別資料

檢視課程

練習說明

  • 使用 catplot() 函式建立點狀圖。
  • "Hotel stars" 作為 x 軸分組。
  • 將要視覺化的數值變數設定為 "Nr. reviews"
  • 調整引數,讓任何出現的連線不會互相重疊。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a point plot with catplot using "Hotel stars" and "Nr. reviews"
sns.catplot(
  # Split the data across Hotel stars and summarize Nr. reviews
  ____,
  ____,
  data=reviews,
  # Specify a point plot
  ____,
  hue="Pool",
  # Make sure the lines and points don't overlap
  ____
)
plt.show()
編輯並執行程式碼