使用具有多索引的数据框创建条形图

Creating bar plot using dataframe with multi-indexing

我有以下数据框:

         Score
one  A     8
     B    19
     D    29
two  C    18
     A    10
     B     4
     D     2
six  C     4
     A     4
     B     4

我希望创建 一个 条形图,其中 X 轴值为 "one"、"two" 和 "six",每个值都有4 个条形图(A、B、C、D),条形图高度由得分列决定。

谢谢。 纳斯佳

尝试以下操作:

df.unstack(level=1).plot(kind='bar')

你需要unstack for reshaping with DataFrame.plot.bar:

import matplotlib.pyplot as plt

df.unstack()['Score'].plot.bar()

plt.show()