【发布时间】:2019-07-09 10:28:32
【问题描述】:
我需要使用 matplotlib 绘制饼图,但我的 DataFrame 有 3 列,即 gender、segment 和 total_amount。
我曾尝试使用 plt.pie() 参数,但它只需要 x 和标签作为数据。我尝试将gender 设置为图例,但它看起来不正确。
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({'gender': {0: 'Female',
1: 'Female',
2: 'Female',
3: 'Male',
4: 'Male',
5: 'Male'},
'Segment': {0: 'Gold',
1: 'Platinum',
2: 'Silver',
3: 'Gold',
4: 'Platinum',
5: 'Silver'},
'total_amount': {0: 2110045.0,
1: 2369722.0,
2: 1897545.0,
3: 2655970.0,
4: 2096445.0,
5: 2347134.0}})
plt.pie(data = df,x="claim_amount",labels="Segment")
plt.legend(d3.gender)
plt.show()
我想要的结果是total_amount 的饼图,其标签为gender 和segment。如果我能得到百分比,那将是一个奖金。
【问题讨论】:
标签: python matplotlib plot data-visualization pie-chart