✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

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