【问题标题】:Python: Plot pie chart for every groups in PandasPython:在 Pandas 中为每个组绘制饼图
【发布时间】:2020-04-21 04:20:21
【问题描述】:

下面是我的数据集分组后检索到的数据框:

df1 = data.groupby(['gender','Segment']).agg(Total_Claim = ('claim_amount', 'sum'))
df1['Total_Claim']=df1['Total_Claim'].astype(int)
df1

同样的输出是:

                    Total_Claim
gender  Segment 
Female  Gold        2110094
        Platinum    2369761
        Silver      1897617
Male    Gold        2699208
        Platinum    2096489
        Silver      2347217

在基于性别和细分的索赔金额合计值之间绘制饼图的最有效方法是什么?

【问题讨论】:

  • 你需要来自样本数据的2饼图吗?
  • @jezrael 是的,我认为这是呈现数据的唯一方式。
  • 是的,这会工作@jezrael

标签: python-3.x pandas pie-chart


【解决方案1】:

您可以获得Series 并通过Series.plot.pieautopct 参数绘制百分比:

df['Total_Claim'].plot.pie(autopct='%1.1f%%')

【讨论】:

  • 如何以百分比显示图表的标签?
  • @GautamMishra - 什么ageage 的示例 DataFrame 中没有数据。
  • 我的意思是百分比!
  • 使用autopct='%1.1f%%' 为百分比工作。谢谢!
猜你喜欢
  • 2023-02-08
  • 2019-06-12
  • 2022-01-19
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2023-01-03
  • 2021-04-21
  • 1970-01-01
相关资源
最近更新 更多