0

I have a list of t-shirt orders along with the corresponding size and I would like to plot them in pie chart for each design showing the percentage in which size sells the most etc.

    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

2 Answers 2

1

It is not complete clear what you asking, but here is my interpretation:

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}')

enter image description here


Maybe you want:

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('');

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Let do groupby.plot.pie:

(df.Design.str.split(expand=True)
   .assign(Total=df['Total'])
   .groupby(0)
   .plot.pie(x=1,y='Total', autopct='%.1f%%')
)

# format the plots
for design, ax in s.iteritems():
    ax.set_title(design)

one of the output:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.