AttributeError: module 'plotly.express' has no attribute 'Constant'

AttributeError: module 'plotly.express' has no attribute 'Constant'

伙计们!

我正在使用 Google Colab 来进一步研究数据科学。当我尝试使用 Plotly Express 生成图表时,出现以下错误:

AttributeError: module 'plotly.express' has no attribute 'Constant'

我要生成的图表是:

sample  = df.rename(columns={"location":"Location","num_sequences_total":"Number of Case"})
fig = px.treemap(sample, path=[px.Constant('Number of Case'),'Location'], values='Number of Case',
                   hover_data=['Location'])
fig.show()

我导入的库是:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
import statsmodels.api as sm
import pandas_profiling
import plotly.express as px

我尝试使用 ! pip install --upgrade plotly 升级 Plotly,但效果不佳。

你知道我做错了什么吗?

干杯, 马塞洛

好的,既然你没有提供那么多其他信息,有两个想法:

  1. 升级 PIP(pip 本身,不是 plotly)并重新安装 plotly:$ python -m pip install --upgrade pip
  2. 您可以尝试导入子模块:from plotly import express as px(未测试)