treemap AttributeError: 'DataFrame' object has no attribute 'append'
I try to run this code of the example from the guide page
import plotly.express as px
df = px.data.tips()
fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
values='total_bill', color='time')
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()
but it just gives an error
File ...\Python310\lib\site-packages\plotly\express\_core.py:1637, in process_dataframe_hierarchy(args)
[1635](.../Python310/lib/site-packages/plotly/express/_core.py:1635) if cols:
[1636](.../Python310/lib/site-packages/plotly/express/_core.py:1636) df_tree[cols] = dfg[cols]
-> [1637](.../Python310/lib/site-packages/plotly/express/_core.py:1637) df_all_trees = df_all_trees.append(df_tree, ignore_index=True)
[1639](.../Python310/lib/site-packages/plotly/express/_core.py:1639) # we want to make sure than (?) is the first color of the sequence
[1640](.../Python310/lib/site-packages/plotly/express/_core.py:1640) if args["color"] and discrete_color:
File c:\Users\stepa\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py:5989, in NDFrame.__getattr__(self, name)
[5982](.../Python310/lib/site-packages/pandas/core/generic.py:5982) if (
[5983](.../Python310/lib/site-packages/pandas/core/generic.py:5983) name not in self._internal_names_set
[5984](.../Python310/lib/site-packages/pandas/core/generic.py:5984) and name not in self._metadata
[5985](../Python310/lib/site-packages/pandas/core/generic.py:5985) and name not in self._accessors
[5986](.../Python310/lib/site-packages/pandas/core/generic.py:5986) and self._info_axis._can_hold_identifiers_and_holds_name(name)
[5987](.../Python310/lib/site-packages/pandas/core/generic.py:5987) ):
[5988](.../Python310/lib/site-packages/pandas/core/generic.py:5988) return self[name]
-> [5989](.../Python310/lib/site-packages/pandas/core/generic.py:5989) return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'append'
pandas=2.2.2 plotly.express=0.4.1 plotly=5.24.0
Interesting...when running it in google collab with the specified package versions that you had, it appears to work for me and didn't raise the error you mentioned. see here
Looking more specifically at the error, I believe the DataFrame.append() has been depreciated in favour of DataFrame.concat() so replacing it accordingly on line 1637 should fix this but would be interested to see if this issue occurs for others.
Hi @StepanSushko, what kind of environment are you running this in? Is it a notebook? This was fixed a while ago in Plotly, so it feels like the environment might be picking up the wrong version.
Are the versions you mention what you see when you run pip list?
If you are in a notebook, what does this output?
import plotly
plotly.__version__
this looks fine now
i think it can be closed?