Hi all.
I’ve discovered a pretty strange behaviour in plotly.express charts: they ignore negative values in pandas dataframes completely.
For instance, I create a plotly.express chart with a dataframe.
df = pd.read_sql(sql, engine)
fig= px.pie(dff, values=‘fatt_netto’, names=‘classe1’, title=‘FN’)
Then I load my pie chart inside a dash app.
If, for instance, I select the ‘AUDIO’ category I get a value for ‘fatt_netto’ of 1,534,980.83
But if I query the database I get a different value:
If I don’t select the negative values I get 1,534,980.83
If I check dataframe I pass to px.pie I see that dff does contains the negative values
print(dff[dff[‘fatt_netto’] < 0])
fig= px.pie(dff, values=‘fatt_netto’, names=‘classe1’, title=‘FN’)
And to be more precise, If I sum the negative values I get exactly the difference -33,317.6
a = dff[dff['fatt_netto'] < 0]
print(a.groupby(['classe1']).sum())
1,501,663.23 - 1,534,980.83 = -33,317.6
That is, the plotly.express chart is ignoring the negative values in the dataframe all together.
How do you handle these negative values?
How do I have to configure plotly to handle negative values?
Many thanks for your time.
Kind regards.
Gius.