pandas - 绘制具有不同字符串组的多个绘图饼图
问题描述
我有一个 T 恤订单列表以及相应的尺寸,我想将它们绘制在饼图中,为每个设计显示尺寸销售最多的百分比等。
Design Total
0 Boba L 9
1 Boba M 4
2 Boba S 2
3 Boba XL 5
4 Burger L 6
5 Burger M 2
6 Burger S 3
7 Burger XL 1
8 Donut L 5
9 Donut M 9
10 Donut S 2
11 Donut XL 5
解决方案
目前尚不清楚您的要求,但这是我的解释:
df[['Design', 'Size']] = df['Design'].str.rsplit(n=1, expand=True)
fig, ax = plt.subplots(1, 3, figsize=(10,8))
ax = iter(ax)
for t, g in df.groupby('Design'):
g.set_index('Size')['Total'].plot.pie(ax=next(ax), autopct='%.2f', title=f'{t}')
也许你想要:
df = pd.read_clipboard() #create data from above text no modification
dfplot = df.loc[df.groupby(df['Design'].str.rsplit(n=1).str[0])['Total'].idxmax(), :]
ax = dfplot.set_index('Design')['Total'].plot.pie(autopct='%.2f')
ax.set_ylabel('');
推荐阅读
- angular - Angular 2 - 根路径路由器的多个参数
- azure - jwt 令牌缺少 adal azure 委托的范围
- python - 如何让预提交只检查您更改的python代码,而不是整个文件
- javascript - 开玩笑的错误,不是 promise 的函数
- javascript - 如何在 Angular 8 中检测文件的字符集?
- node.js - 温斯顿自定义传输格式的消息
- python - Python字符串到类名
- mysql - 具有大型数据集的 Laravel API 加载速度非常慢
- python - Samco API 字典问题
- javascript - 如何在 MVC.Core 中显示漂亮的彩色和可折叠的 json