按名称对数据进行分组、计数并制作饼图

2024-04-25 20:22:11 发布

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

Hello. I need to group data by name, count it and make a pie chart of the percentage share of place names from a given among all names.

链接到我的excel文件:https://drive.google.com/file/d/1gw5mcu3mJXH0Gg4Q-PnRrxDMFq-6VvDo/view?usp=sharing

import pandas as pd                              
import xlrd                                      
import matplotlib.pyplot as plt                  

data = pd.read_excel("table.xlsx", sheet_name=0)

data.groupby('Woj.')['Nazwa miejscowości'].unique().plot(kind='bar')
plt.show()





Tags: oftonameimporthellodatabynames
1条回答
网友
1楼 · 发布于 2024-04-25 20:22:11

我不确定这是否是你问的,请让我知道以防万一。首先,我按名称分组,然后饼图显示每个名称的位数

data.groupby("Woj.")["Nazwa miejscowości"].count().plot.pie(figsize=(10,10),autopct='%1.1f%%')

输出:

enter image description here

相关问题 更多 >