Python: Plot pie chart for every groups in Pandas

Gautam Mishra

Below is the data frame retrieved after grouping my data set:

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

The output of the same is:

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

What would be the most efficient way of plotting a pie chart between the aggregated value of claim amount based on gender and segment?

jezrael

You can get Series and ploting by Series.plot.pie and autopct parameter for percentages:

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

g

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related