"Weights sum to zero, can’t be normalized" Error in treemap of plotly.express

9k Views Asked by At

I am applying treemap function of plothly.express with COVID-19 data.

fig = px.treemap(df_tm, path=['world', 'continent', 'Country_Region'], values='Fatalities',
                  color='Fatalities', hover_data=['Country_Region'],
                  color_continuous_scale='dense', title='Current share of Worldwide COVID19 Cases')

However, I get 'Weights sum to zero, can’t be normalized' error message. So, In order to solve this problem, I check my data, but there is no negative balance.

I don't know what to do. I study this with kaggle data.

https://www.kaggle.com/anshuls235/covid19-explained-through-visualizations

1

There are 1 best solutions below

1
On

Just stumbled into the same problem, and my solution was: just checking for negative balances is not enough. You must also eliminate rows in the data frame you use for the plot that have a zero value in the column that is passed as value to the treemap plot function. Which makes sense: it's hard to print a zero area! So my solution basically was to run

df_plot = df_plot[df_plot['value']!=0]

before calling px.treemap (with the column "value" in df_plot containing the values for the treemap)....and that solved the problem for me.