Help Pie chart Plotly

Hey! I started using Plotly just recently and I’m trying to plot data of a supply chain most sale categories with the next code:

cat = data.groupby([ā€˜Category Name’])[ā€˜Sales per customer’].sum().reset_index().sort_values(ā€˜Sales per customer’)
fig = px.pie(cat, values=ā€˜Sales per customer’, names=ā€˜Category Name’, title=ā€˜Categorias con mas ventas’)
fig.show()

And I get all the categories but Ijust want the top 10

Welcome to Dash @eric7
Maybe you can filter your dataframe before creating the figure, so it has the top 10 of the category you want. For example, for top 10 ā€˜Sales per customer’:

cat = data.groupby([ā€˜Category Name’])[ā€˜Sales per customer’].sum().reset_index().sort_values(ā€˜Sales per customer’)
cat_top_10 = cat.nlargest(10, "Sales per customer")
fig = px.pie(...
1 Like

Hey Adam thank you it worked just fine!! this is how I did:

cat = data.groupby(['Category Name'])['Sales per customer'].sum().reset_index().sort_values('Sales per customer')
cat_top_10 = cat.nlargest(10, "Sales per customer")
fig = px.pie(cat_top_10, values='Sales per customer', names='Category Name', title='Categorias con mas ventas')
fig.show()

1 Like