如何使用熊猫中的数据绘制饼图

发布于 2025-02-07 16:18:04 字数 323 浏览 1 评论 0原文

大家好,

我对Python相对较新。我想绘制部门的饼图,即,有多少人来自sales&营销操作技术等...

我不确定如何先计算各个部门的员工总数,然后仅适用于数据进入饼图。任何帮助将不胜感激!

enter image description here

Hi everyone,

I'm relatively new to python. I want to plot a pie chart for department, i.e., how many percent of the employees coming from Sales & Marketing, Operations, Technology, etc...

I'm not sure how to count the total number of employees from respective department first then only fit the data into the pie chart. Any help will be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此岸叶落 2025-02-14 16:18:04

您可以使用pandas.series.value_counts带有pandas.series.plot.pie

df = pd.DataFrame({"department": ["Sales", "Operations", 
                                  "Sales", "Sales", "Technology"]})
df["department"].value_counts().plot.pie()

output:

You can use pandas.Series.value_counts with pandas.Series.plot.pie:

df = pd.DataFrame({"department": ["Sales", "Operations", 
                                  "Sales", "Sales", "Technology"]})
df["department"].value_counts().plot.pie()

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文