如何使用熊猫绘制选定的列?

时间:2021-07-22 10:36:39

标签: python pandas dataframe matplotlib jupyter-notebook

我只想绘制 2 个国家/地区,以便比较两者之间的差异,但我不知道如何将其添加到我的代码中?

df.plot.bar(x='country'); // 它显示了所有的国家和它的值

enter image description here

我只想展示两个国家。

1 个答案:

答案 0 :(得分:1)

您可以过滤这两个国家。假设这两个国家被称为 country acountry b

mask = (df["Country"] == "country a") | (df["Country"] == "country b")
df[mask].plot.bar(x="country")