Sunburst Chart and values - ValueError: All arguments should have the same length. The length of argument `values` is 360, whereas the length of previously-processed arguments ['risk_types'] is 1145

I am trying to get a sunburst chart to show the actual unique values for an item and not just the count.
In my live data I have a data frame I have made from an excel spreadsheet. This dataframe has 1145 rows. These rows are made from exploding the merged cells in an excel spreadsheet. In its unexploded form I have 360 unique 'risk_id’s but when I plot it, it shows 1145 in the center.

How do I get it to show the unique values. The center should show a total of 360 when filtering correctly

I have the following but it throws a value error telling me - “ValueError: All arguments should have the same length. The length of argument values is 360, whereas the length of previously-processed arguments [‘risk_types’] is 1145”

# Create a dataframe for us to use
sunburst_df = raca_df[['risk_types', 'risk', 'level3', 'risk_id']]
a = 'Group'
sunburst_df['company'] =a


c = sunburst_df['risk_id'].unique()
# now build out our chart
fig = px.sunburst(
    data_frame=sunburst_df,
    path=['company','risk_types','risk','level3'],
    color_continuous_scale=px.colors.sequential.BuGn,
    maxdepth=2,
    values=c,
    #branchvalues='total', # other option is 'remainder'
    hover_name='risk_types',
    title='Breakdown of Risk to Group by Risk Type',
    template='presentation'
)

fig.update_layout(title_x=0.5, height = 900, uniformtext=dict(minsize=10))
fig.update_traces(textinfo='label+percent parent+value', insidetextorientation='radial')
fig.show()

If I go with the basic example using m,y data it fills out ok just the count under group is wrong

Hi @twelsh37
I’m not sure how to completely fix it. But the problem is the “values” parameter. Because you’re assigning it only the unique values, it is receiving less data than the other parameters that are based on sunburst_df. That’s why “All arguments should have the same length”.

Is there a way you can filter the dataframe to have only unique rows, and use only that dataframe throughout the whole sunburst?

Thanks Adam,

Yeah I spotted that. I will go have a go at that later.

Actually, now thinking about it I think I need to modify what data I use to create the sunburst_df dataframe.

The original data was sent to me in an excel file with merged cells. There were 340 unique risk_id’s.

I took the excel file and unmerged the contents so a risk that took originaly up 1 row of merged cells and had 1 risk_id now takes up 10 rows and has the risk_id copied into each row.

I think if I recreate the sunburst_df just using the raca_df[‘risk_id’].unique() as my method of selecting the data it should create a df with what I want.

Who says getting away from the computer whilst thinking on a problem dosent work.

1 Like