nil*_*ore 8 python pandas plotly nbformat
我试图在 Visual Studio Code 中打印一个情节图并发现了这个错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-e07b5feb5ded> in <module>
30
31 fig.update_layout(height=nrows*500)
---> 32 fig.show()
C:\Python38\lib\site-packages\plotly\basedatatypes.py in show(self, *args, **kwargs)
3147 import plotly.io as pio
3148
-> 3149 return pio.show(self, *args, **kwargs)
3150
3151 def to_json(self, *args, **kwargs):
C:\Python38\lib\site-packages\plotly\io\_renderers.py in show(fig, renderer, validate, **kwargs)
383
384 if not nbformat or LooseVersion(nbformat.__version__) < LooseVersion("4.2.0"):
--> 385 raise ValueError(
386 "Mime type rendering requires nbformat>=4.2.0 but it is not installed"
387 )
ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
Run Code Online (Sandbox Code Playgroud)
我使用的代码:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.express as px
df = df[df['Data']>0]
df['Timestamp'] = pd.to_datetime(df['Timestamp'])
df = df[(df['Id'] ==1)|(df['Id'] ==6)]
dfp = pd.pivot_table(df,
values='Data',
index=['Timestamp'],
columns=['Id'],
)
nrows = len(dfp.columns)
fig = make_subplots(rows=nrows,
cols=1,
subplot_titles=['Id '+str(c) for c in dfp.columns])
# add traces
x = 1
for i, col in enumerate(dfp.columns):
fig.add_trace(go.Scatter(x=dfp.index, y=dfp[col].values,
name = 'Id '+str(col),
mode = 'lines',
),
row=i+1,
col=1)
fig.update_layout(height=nrows*500)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我在 GitHub 上的这个提要和stackoverflow上的这个问题之后在pip install nbformat控制台中尝试过,
但它没有用。
但是,代码似乎可以在删除最后 2 行的情况下运行:
fig.update_layout(height=nrows*500)
fig.show()
Run Code Online (Sandbox Code Playgroud)
Ara*_*d R 63
!pip install nbformat
Run Code Online (Sandbox Code Playgroud)
小智 15
方法一。
通过重新安装 ipykernel pipenv install ipykernel
方法二。
pip install --upgrade nbformat
Run Code Online (Sandbox Code Playgroud)
对于那些使用 conda 的人来说,这对我有用:
验证您的 conda 环境的名称:
conda info --envs
假设它是“myenv”,继续:
conda activate myenv
conda install nbformat
然后重新启动内核。