下面是对我的数据集进行分组后检索到的数据框:
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
根据性别和分类在索赔金额的合计值之间绘制饼图的最有效方法是什么?
您可以获得Series
并通过Series.plot.pie
进行绘图:
Series.plot.pie
df['Total_Claim'].plot.pie()
gender
df['Total_Claim'].unstack(0).plot.pie(subplots=True)