如何在pandas dataframe中更改Y轴

2024-05-19 09:14:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下清单:

[('und', 52),
 ('die', 36),
 ('von', 33),
 ('der', 29),
 ('in', 20),
 ('das', 17),
 ('für', 17),
 ('eine', 15),
 ('des', 14),
 ('Die', 14),
 ('ODP', 14),
 ('wurde', 13),
 ('zu', 13)]

使用以下代码,我将其转换为熊猫数据帧:

^{pr2}$

然后我把它画出来:

fig, ax_lst = plt.subplots(1,1)  # a figure with a 2x2 grid of Axes

df10 = df.copy()

df10 = df[:20]

df10.Vorkommen.plot(kind='barh')
plt.show()

如何将y轴从索引更改为单词?在

enter image description here


Tags: indfpltzudesderdieodp
2条回答

默认情况下,plot.barh使用索引。可以如下显式设置x和y值:

df10.plot.barh(x='Wort', y='Vorkommen')

您可以使用^{}
^默认情况下,{}将使用DataFrame的索引作为标签。在

df10.set_index('Wort').Vorkommen.plot(kind='barh')

相关问题 更多 >

    热门问题