The dataframe i’m using to create the tree graph has both parent and children cells empty sometimes. After modifing them to ‘none’, the tree graph works, but it displays all the ‘none’ parents and childrens, wich make the graph a bit confusing and less pretty. The only solution i could think was to modify the dataframe, bringing the children cells back, placing them on the empty cells. But i would like to know if there is, i dont know, a buil-in way for plotly to ignore the empty cells on tree graphs somehow ?
def grafico_arvore(dataframe):
import plotly.express as px
import numpy as np
import pandas as pd
df = dataframe
df=df.fillna('none')
#df["world"] = "world" # in order to have a single root node
fig = px.treemap(df, path=['categoria1', 'categoria2'], values='gastos',
color='teto', hover_data=['categoria2'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['teto'], weights=df['gastos']))
fig.show()
Part of the dataframe alredy modified to replace the empty cells with ‘none’: