我想创建一个饼图,显示各国家的数值。我有一个单列csv文件,其中包含用户来自哪些国家的列表,我将其读入pandas数据帧中。 我尝试了各种网络上的饼图教程,但无法绘制此单列数据。
fig = plt.pyplot.figure()
ax = fig.add_subplot(111)
ax.hist(country)
数据示例:
country
0 BRAZIL
1 INDIA
2 INDIA
3 CHINA
4 RUSSIA
5 BRAZIL
我想创建一个饼图,显示各国家的数值。我有一个单列csv文件,其中包含用户来自哪些国家的列表,我将其读入pandas数据帧中。 我尝试了各种网络上的饼图教程,但无法绘制此单列数据。
fig = plt.pyplot.figure()
ax = fig.add_subplot(111)
ax.hist(country)
数据示例:
country
0 BRAZIL
1 INDIA
2 INDIA
3 CHINA
4 RUSSIA
5 BRAZIL
import pandas as pd
import matplotlib.pyplot as plt
#import your data here
#Plot a histogram of frequencies
df.country.value_counts().plot(kind='barh')
plt.title('Number of appearances in dataset')
plt.xlabel('Frequency')
#Now make a pie chart
df.country.value_counts().plot(kind='pie')
plt.axis('equal')
plt.title('Number of appearances in dataset')