我有一个像这样的小熊猫数据框:
Word Percentage1 Percentage2
1 drink 18.166654 29.014272
2 cherry 13.498262 12.802642
3 berry 9.810123 6.775552
4 plum 7.964429 7.105845
5 crisp 7.892941 4.715009
...
50 spices 0.856775 1.663586
Run Code Online (Sandbox Code Playgroud)
单词 (50) 和带有数字对应的两列,每列表示该单词的发生率。如何制作聚类图表以显示每个单词的两个数字的比较?我已经尝试了几乎所有在本网站上提供给其他人的代码,我只是不明白如何对两个“百分比”列进行分组。
如果我理解正确,你可以这样做:
df.plot(x="Word", y=["Percentage1", "Percentage2"], kind="bar")
Run Code Online (Sandbox Code Playgroud)
尝试这个,
df.set_index('Word').plot(kind='bar')
Run Code Online (Sandbox Code Playgroud)
开/关
如果您不想为 df 中的所有值列执行图表,请使用它。只需设置索引作为X,其余所有列作为y
输入:
Word Percentage1 Percentage2 Percentage3 Percentage4
0 drink 18.166654 29.014272 7.105845 29.014272
1 cherry 13.498262 12.802642 4.715009 12.802642
2 berry 9.810123 6.775552 6.097997 3.408988
3 plum 7.964429 7.105845 12.802642 19.620618
4 crisp 7.892941 4.715009 6.775552 35.832248
Run Code Online (Sandbox Code Playgroud)
开/关