建立長條圖
拉斯維加斯的飯店在「評論對其他人是否有幫助」這件事上出現很大差異。這些飯店的業主想知道,一年當中是否有某些時段的評論對潛在房客更有幫助。請透過在類別變數 "Period of stay" 上,製作每則評論平均 "Helpful votes" 的長條圖,幫助業主更了解他們的評論。reviews 資料集已為你預先載入。
本練習屬於課程
在 Python 中處理類別資料
練習說明
- 列印變數
"Period of stay"的次數統計,確認每個類別都有資料。 - 使用
catplot()建立長條圖。 - 在 x 軸依據
"Period of stay"將reviews資料集分組。 - 將要彙總的數值變數指定為
"Helpful votes"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the frequency counts of "Period of stay"
print(reviews[____].____)
sns.set(font_scale=1.4)
sns.set_style("whitegrid")
# Create a bar plot of "Helpful votes" by "Period of stay"
sns.catplot(____)
plt.show()