熊猫数据框多列条形图

时间:2020-06-17 10:05:05

标签: python pandas bar-chart

我正在尝试创建一个在数据框中包含多列的条形图。我的数据框看起来像这样。

a = """ _ommited everythig: *ignore everything beyond*
    createTime: 2020-06-03T16:01:35.812Z --only this line to be selected
    employee:
      _id: 835537164084782 -- ID that is used as a reference to return 'createTime' two lines above
      code: null """
x = re.compile('([^\n]*\n[^\n]*\n)[^\n]*8355371640847')
print (x.findall(a))
x = re.compile('([^\n]*\n)[^\n]*\n[^\n]*8355371640847')
print (x.findall(a))

所需的输出 Chart

1 个答案:

答案 0 :(得分:1)

先按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()