敬启者,
我在从学校的练习中重新创建特定的旭日形图时遇到问题。
希望有人能够提供帮助。非常感谢。
我的代码
fig_1 = px.sunburst(top_neighbourhood_df, path=[top_neighbourhood_df.index, "neighbourhood"], values="shelter_costs_rented",
color="shelter_costs_rented", hover_data=["shelter_costs_rented"],
color_continuous_scale='InFerno',
color_continuous_midpoint=np.average(top_neighbourhood_df["shelter_costs_rented"], weights=top_neighbourhood_df["shelter_costs_rented"]),
title = "Costs Analysis of Most Expensive Neighbourhood in Toronto per Year - Shelter_costs_rented")
fig_1.show()
输出错误
AttributeError: type object 'object' has no attribute 'dtype'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-35-e364e04b8104> in <module>
3 color_continuous_scale='InFerno',
4 color_continuous_midpoint=np.average(top_neighbourhood_df["shelter_costs_rented"], weights=top_neighbourhood_df["shelter_costs_rented"]),
----> 5 title = "Costs Analysis of Most Expensive Neighbourhood in Toronto per Year - Shelter_costs_rented")
6 fig_2.show()
D:\ProgramData\Anaconda3\envs\pyvizenv\lib\site-packages\plotly\express\_chart_types.py in sunburst(data_frame, names, values, parents, path, ids, 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)
1416 constructor=go.Sunburst,
1417 trace_patch=dict(branchvalues=branchvalues, maxdepth=maxdepth),
-> 1418 layout_patch=layout_patch,
1419 )
1420
D:\ProgramData\Anaconda3\envs\pyvizenv\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
D:\ProgramData\Anaconda3\envs\pyvizenv\lib\site-packages\plotly\express\_core.py in process_dataframe_hierarchy(args)
1568 cols = list(set(cols) - set(["labels", "parent", "id"]))
1569 # ----------------------------------------------------------------------------
-> 1570 df_all_trees = pd.DataFrame(columns=["labels", "parent", "id"] + cols)
1571 # Set column type here (useful for continuous vs discrete colorscale)
1572 for col in cols:
D:\ProgramData\Anaconda3\envs\pyvizenv\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
390 dtype=dtype, copy=copy)
391 elif isinstance(data, dict):
--> 392 mgr = init_dict(data, index, columns, dtype=dtype)
393 elif isinstance(data, ma.MaskedArray):
394 import numpy.ma.mrecords as mrecords
D:\ProgramData\Anaconda3\envs\pyvizenv\lib\site-packages\pandas\core\internals\construction.py in init_dict(data, index, columns, dtype)
194 nan_dtype = dtype
195 val = construct_1d_arraylike_from_scalar(np.nan, len(index),
--> 196 nan_dtype)
197 arrays.loc[missing] = [val] * missing.sum()
198
D:\ProgramData\Anaconda3\envs\pyvizenv\lib\site-packages\pandas\core\dtypes\cast.py in construct_1d_arraylike_from_scalar(value, length, dtype)
1173 else:
1174 if not isinstance(dtype, (np.dtype, type(np.dtype))):
-> 1175 dtype = dtype.dtype
1176
1177 if length and is_integer_dtype(dtype) and isna(value):
AttributeError: type object 'object' has no attribute 'dtype'