Python:为Pandas中的每个组绘制饼图
Python: Plot pie chart for every groups in Pandas
下面是对我的数据集进行分组后检索到的数据框:
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
和 autopct
参数绘制百分比:
df['Total_Claim'].plot.pie(autopct='%1.1f%%')
下面是对我的数据集进行分组后检索到的数据框:
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
和 autopct
参数绘制百分比:
df['Total_Claim'].plot.pie(autopct='%1.1f%%')