Error while visualizing data with countplot?
Question:
Since there is a categorical data in the picture here, it wants me to convert it, but I want to make the categorical data count
i need to plot countplot of how many should be from which country but i get valuerror error
Answers:
You can use value_counts
method:
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()
Since there is a categorical data in the picture here, it wants me to convert it, but I want to make the categorical data count
i need to plot countplot of how many should be from which country but i get valuerror error
You can use value_counts
method:
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()