python - 熊猫数据框多列条形图
问题描述
我正在尝试在数据框中创建一个包含多列的条形图。我的数据框看起来像这样。
Age Index 1 Index 2 Index 3 Index 4
18-30 20.000000 0.000000 0.000000 5.000000
31-40 27.807487 6.746195 2.694364 1.069519
41-50 45.499022 6.849315 1.663405 3.228963
51-60 41.176471 0.000000 0.000000 11.764706
解决方案
按列创建索引Age
(如有必要),然后按rename
列和最后使用DataFrame.plot.bar
:
d = {'Index 1':'Payment', 'Index 2':'Gender Focus',
'Index 3':'H&S General', 'Index 4': 'H&S Covid 19'}
df.set_index('Age').rename(columns=d).plot.bar()
推荐阅读
- node.js - 将管道与 Electron ClientRequest 模块一起使用
- sql - SQL 修剪第一个和最后一个字符串指示器的所有内容
- javascript - 返回对nodejs中调用函数的html响应
- docker - Docker:带有 LetsEncrypt 的 HTTPS 代理
- wordpress - Wordpress:显示自定义帖子类型的父页面及其兄弟页面
- java - stanford nlp 共指解析错误:线程“主”java.lang.IllegalArgumentException 中的异常:文件不存在:example_file.txt
- angularjs - 抽象状态控制器的 $scope 在离开时不会被破坏 - AngularJS
- xamarin.forms - Xam 插件:CrossLocalNotifications.Current.Show 在三星 S8 上不起作用(最新更新后)
- haskell - 斐波那契函数的惰性求值
- android - 带有圆角边缘的按钮动态背景颜色