python - x 轴上的分组条形图
问题描述
我有个问题。我想打印一个分组条形图(使用 seaborn 或 matplotlib)。当我运行下面的代码片段时,我得到了
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
d = {'type': ['House', 'Boat', 'Bus', 'Bus', 'Boat'], 'room': ['private', 'public', 'public', 'private', 'nothing']}
df = pd.DataFrame(data=d)
print(df)
[OUT]
type room
0 House private
1 Boat public
2 Bus public
3 Bus private
4 Boat nothing
g = sns.catplot(
data=df, kind="bar",
x='type', y=df.groupby(['type']).count(), hue="room",
palette="dark", alpha=.6, height=6
)
g.despine(left=True)
g.set_axis_labels("", "Counts")
g.legend.set_title("")
[OUT]
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我想要的是
解决方案
推荐阅读
- typescript - @typescript-eslint 中的任何标准方法可以将返回值转换为 'any' 而不会收到 'no-explicit-any' 警告?
- javascript - 如何在 Laravel 的帮助下将 HTML 表单输入中的值相加
- wordpress - WordPress + Gatsby 自定义休息路线未在 GraphQL 中显示
- python - 使用标量使用 tf.Data 加载图像 Tensorflow 会引发异常
- javascript - 如何循环浏览一组图片
- firebase - 为什么 dataSnapshot 在 ViewModel 中反序列化,而不是在扩展 LiveData 的类中?
- c - C:处理二维数组的列
- powershell - 在 PowerShell 中使用“使用”语句的任何动态方式?
- .net - 函数参数 VS 私有引用
- java - 设置拦截器仅关闭端点