Reputation: 37
I am trying to create a sunburst chart using a pandas dataframe and plotly express.
Here is dataframe, keep in mind this is only the first 10 rows, once it finishes with the suburbs for 2001, it jumps to the same suburbs for 2006, 2011, 2016
And here is my code
sunburst_chart = px.sunburst(
sunburst_data,
path=["year", "neighbourhood"],
values="average_house_value",
names="neighbourhood",
)
sunburst_chart.show()
The error that is gives me is AttributeError: type object 'object' has no attribute 'dtype'
and is referring to names="neighbourhood"
but if I remove that line the error points to the line above, and repeat.
There are no duplicate rows, no nulls and the dtypes are
year int64
neighbourhood object
average_house_value int64
dtype: object
Any help is much appreciated, thank you
Upvotes: 1
Views: 1046
Reputation: 19600
Based on this issue and this bug report, I believe this is a numpy and pandas related bug that should be solved if you upgrade to the latest version of both libraries.
I created a sample DataFrame with the same columns and data types as yours, and after I downgraded to pandas 0.25.3 / numpy 1.20.0
, I was able to reproduce your error:
AttributeError: type object 'object' has no attribute 'dtype'.
When I upgraded both libraries to numpy 1.21.0 / pandas 1.1.0
, I was able to generate a sunburst plot:
import pandas as pd
import plotly.express as px
sunburst_data = pd.DataFrame({
'year':[2001]*4 + [2002]*4 + [2003]*4,
'neighbourhood': list('abcdefghijkl'),
'average_house_value': list(range(100000,220000,10000))
})
sunburst_chart = px.sunburst(
sunburst_data,
path=["year", "neighbourhood"],
values="average_house_value",
names="neighbourhood",
)
sunburst_chart.show()
Upvotes: 2