无法在pycharm中使用plotly绘制pandas数据帧数据

问题描述 投票:1回答:1

我试图在pycharm中使用plotly绘制一个pandas数据帧数据,但它无法正常工作。以下是代码段。

import plotly.plotly as py
import pandas as pd
import numpy as np
import cufflinks as cf

cf.go_offline()

df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
print(df.head())

df.iplot()

当我在pycharm中运行上面的代码时,它会抛出错误

plotly.exceptions.PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.
Run help on this function for more information.

不确定这里究竟出了什么问题。

谁能帮我这个?

谢谢。

pandas dataframe pycharm plotly
1个回答
0
投票

您的代码完全按原样在Jupyter笔记本中运行并生成此图:

enter image description here

所以问题归结为你如何在PyCharm中运行你的代码。一个Python控制台?也许是IPython?为了使plotly和iplot()脱机工作,我认为你必须在Jupyter笔记本中运行这个特定的片段。但你可以在PyCharm中做到这一点,以及unider File > New > Jupyter Notebook:

enter image description here

您可能需要进行一些额外的安装,但这根本不应该太难。

© www.soinside.com 2019 - 2024. All rights reserved.