Python:为熊猫中的每个组绘制饼图

问题描述 投票:0回答:1

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

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

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

python-3.x pandas pie-chart
1个回答
0
投票

您可以获得Series并通过Series.plot.pie进行绘图:

Series.plot.pie

df['Total_Claim'].plot.pie()

对于每个g使用2个图表:

gender

df['Total_Claim'].unstack(0).plot.pie(subplots=True)

© www.soinside.com 2019 - 2024. All rights reserved.