Plotly tree graph showing wrong python values

Asked

Viewed 31 times

2

That boy-girl Sunburst plotly, when used in a dataframe of this spreadsheet, through the code below, generates a graph wrong values of the 'rest' column. For example, in the path 'expense/service/electricity', in the spreadsheet, the graph should show under the variable 'rest' the sum of 299 and 49, which are the values in the spreadsheet under the column 'rest' that correspond to the path mentioned. But it shows a value wrong, 263,287(...). The same error is repeated in several ways, and not only in this way.

I believe that the code below is not asking for the value corresponding to color ( represented by the column 'rest') to have its value defined by the sum of all cells in this column ('rest') and path ( for example 'expense/service/electricity'). It must be doing some other calculation that I did not identify ... And there must be a way to ask to add, but I do not know how.

import plotly.express as px
import numpy as np
import pandas as pd
df = pd.read_csv('vai.csv')
fig = px.sunburst(df, path=['renda_despesa','categoria1', 'categoria2','categoria3'], values='teto',
                          color='resto', hover_data=['categoria3'],
                          color_continuous_scale='RdBu',
                          color_continuous_midpoint=np.average(df['resto'], weights=df['teto']),
                          branchvalues="total")    
fig.show()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.