python 使用countplot可视化数据时出错?

zpf6vheq  于 2023-04-04  发布在  Python
关注(0)|答案(1)|浏览(199)

enter image description here
由于这里的图片中有一个分类数据,它希望我转换它,但我希望使分类数据计数
我需要绘制countplot的多少应该是从哪个国家,但我得到valuerror错误

5lwkijsr

5lwkijsr1#

你可以使用value_counts方法:

from matplotlib import pyplot as plt

# get count of categorical values
counts = df2021['Regional indicator'].value_counts()

# make a bar plot (you can use some other plot, too)
plt.bar(counts.index, counts)

# make your xticks clearly visible (you can try different angles)
plt.xticks(rotation=90)

plt.show()

相关问题