I commented out the check in plotly/express/_core.py and it worked.
See:
def _check_dataframe_all_leaves(df):
df_sorted = df.sort_values(by=list(df.columns))
null_mask = df_sorted.isnull()
df_sorted = df_sorted.astype(str)
null_indices = np.nonzero(null_mask.any(axis=1).values)[0]
for null_row_index in null_indices:
row = null_mask.iloc[null_row_index]
i = np.nonzero(row.values)[0][0]
if not row[i:].all():
raise ValueError(
"None entries cannot have not-None children",
df_sorted.iloc[null_row_index],
)
df_sorted[null_mask] = ""
row_strings = list(df_sorted.apply(lambda x: "".join(x), axis=1))
#for i, row in enumerate(row_strings[:-1]):
#if row_strings[i + 1] in row and (i + 1) in null_indices:
#raise ValueError(
# "Non-leaves rows are not permitted in the dataframe \n",
# df_sorted.iloc[i + 1],
# "is not a leaf.",
#)
My diagram renders perfectly. It would be great if there was an ignore_non_leaves=True option, rather than my horrible hack!
> 0 1 2 3 4
0 alice bob smith NaN NaN
0 alice bob smith rocky NaN
0 alice bob chuck david ella
0 alice bob chuck david fred
0 alice bob chuck NaN NaN
This is more specific to my current scenario, by doing dropna() i will lose rows branching out from bob to smith. Smith and Chuck are two children belonging to Bob, how do i visualize a treemap/sunburst in such scenario without filling NaN with some dummy text
This is because the DataFrame expected needs to be rectangular. With each column having a value to group by. In the docs, you have an example with a dataframe grouped by day, then by time and then by sex.
In your case, I think it would be easier to just use names and parents instead of passing a DataFrame.