I'm trying to create a a treemap in Plotly Express. If I manually enter the column names, the treemap is created. Passing a list of the same column names throws a ValueError.
Essentially I have a dataframe with column names 3,4,5,6,7,8,9,10
Because these column names will vary depending on the data, I'd like to pass these as a list to Plotly express.
Manually entering them as per below, will work
treemap_fig = px.treemap(df_split_folders, path=[px.Constant("Chart Title"), 3,4,5,6,7,8,9,10],values='count', color_discrete_sequence=px.colors.qualitative.Antique)
but passing them as a list does not. E.g
# create list of column names from dataframe
total_cols = df_split_folders.columns.values.tolist()
#pass as a list
treemap_fig = px.treemap(df_split_folders, path=[px.Constant("Chart Title"), 3,4,5,6,7,8,9,10],values='count', color_discrete_sequence=px.colors.qualitative.Antique)
I've also tried converting the column name list to a string, but no dice.
Edit: Here is a Minimum Reproducible Example:
import pandas as pd
import plotly.express as px
# dictionary with list object in values
details = {
'url' : ['/category', '/category', '/product', '/product'],
'folder' : ['/games', '/playstation', '/cars', '/cycling'],
'type' : ['adventure', 'action', 'action', 'adventure'],
}
df = pd.DataFrame(details, index = ['a', 'b', 'c', 'd'])
df['count'] = 1
treemap_fig = px.treemap(df, path=[px.Constant("Discovered / Crawled Not Indexed"), 'url', 'folder', 'type'], values='count', color_discrete_sequence=px.colors.qualitative.Antique)
treemap_fig.show()
this code works as expected and produces a treemap, however - if I try and pass the column names as a variable, it no longer references the dataframe column names. e.g.
cols = 'url', 'folder', 'type'
treemap_fig = px.treemap(df, path=[px.Constant("Discovered / Crawled Not Indexed"), **cols**], values='count', color_discrete_sequence=px.colors.qualitative.Antique)
treemap_fig.show()