Non-leaves rows are not permitted in the dataframe \n, I still have no clue how to deal with the treemap "leaf" attribute

Viewed 204

I've read some answers related the "non-leaf" problem to the treemap but still cannot understand the context. it is my code:

## Tree Plot
import plotly.express as px
Titanic["Titanic"]="Titanic"                             ## Add an universal root
Titanic["value"]=1
fig=px.treemap(Titanic,path=["Titanic","Survived","Sex","Embarked"],
              values="value",color="Fare",color_continuous_scale='RdBu',width=800,height=500,)
fig.show()

And this is the error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7692/3598846156.py in <module>
      3 Titanic["Titanic"]="Titanic"                             ## Add an univfersal root
      4 Titanic["value"]=1
----> 5 fig=px.treemap(Titanic,path=["Titanic","Survived","Sex","Embarked"],
      6               values="value",color="Fare",color_continuous_scale='RdBu',width=800,height=500,)
      7 fig.show()

C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_chart_types.py in treemap(data_frame, names, values, parents, ids, path, color, color_continuous_scale, range_color, color_continuous_midpoint, color_discrete_sequence, color_discrete_map, hover_name, hover_data, custom_data, labels, title, template, width, height, branchvalues, maxdepth)
   1462     if path is not None and branchvalues is None:
   1463         branchvalues = "total"
-> 1464     return make_figure(
   1465         args=locals(),
   1466         constructor=go.Treemap,

C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py in make_figure(args, constructor, trace_patch, layout_patch)
   1861     args = build_dataframe(args, constructor)
   1862     if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
-> 1863         args = process_dataframe_hierarchy(args)
   1864     if constructor == "timeline":
   1865         constructor = go.Bar

C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py in process_dataframe_hierarchy(args)
   1500     df = args["data_frame"]
   1501     path = args["path"][::-1]
-> 1502     _check_dataframe_all_leaves(df[path[::-1]])
   1503     discrete_color = False
   1504 

C:\ProgramData\Anaconda3\lib\site-packages\plotly\express\_core.py in _check_dataframe_all_leaves(df)
   1487     for i, row in enumerate(row_strings[:-1]):
   1488         if row_strings[i + 1] in row and (i + 1) in null_indices:
-> 1489             raise ValueError(
   1490                 "Non-leaves rows are not permitted in the dataframe \n",
   1491                 df_sorted.iloc[i + 1],

ValueError: ('Non-leaves rows are not permitted in the dataframe \n', Titanic     Titanic
Survived          1
Sex          female
Embarked           
Name: 61, dtype: object, 'is not a leaf.')

what's that meaning? what is the parent attribute from?

0 Answers
Related