Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Sunburst Chart - ZeroDivisionError: Weights sum to zero, can't be normalized

Hello - I’m having an issue with increasing the level of granularity in a sunburst chart. The chart renders fine when I limit the path to two levels of granularity (CUR_FIN_CLASS and CUR_PAYOR):

image

but when including an additional path (AGING_BUCKET), I continually receive a ZeroDivisionError. It must be how the px.sunburst function is calculating the outermost slices. Any idea how I might prep the data in the pivot_table call to proof it so when passed into the px.suburst function, I avoid the ZeroDivisionError? Any help would be greatly appreciated!

Here is my code:

def ArSnBrstdf(dataFrame):

df = dataFrame 
df = pd.pivot_table(df, values='OUTSTANDING_AMT',index=['CUR_FIN_CLASS','CUR_PAYOR','AGING_BUCKET'], aggfunc=np.sum,fill_value=None,dropna=True).reset_index()
df['ALL'] = 'PAYOR_DATA'

fig = px.sunburst(df, path=['ALL','CUR_FIN_CLASS','CUR_PAYOR','AGING_BUCKET'],values='OUTSTANDING_AMT',
                    color='OUTSTANDING_AMT',
                    color_continuous_scale='gnbu',
                    )

fig.show()    
#return df

ArSnBrstdf(dfAr)

1 Like

Found the answer. In the outermost level, one of the child slices contained a negative balance so the sunburst was not building. Apologies to anyone that spent time looking at this. The answer is: clean your data!