创建条形图
拉斯维加斯的酒店在"点评对他人是否有用"这一点上差异很大。酒店老板想了解一年中是否存在某些时段,点评对潜在住客更有帮助。请帮助他们更好地理解这些点评:基于分类变量 "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()