首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Plotly ValueError中使用Pandas对象

在Plotly ValueError中使用Pandas对象
EN

Stack Overflow用户
提问于 2018-08-28 20:42:42
回答 1查看 991关注 0票数 2

作为Python课程的一部分,我正在尝试使用Plotly off of a DataFrame创建一个图表。DataFrame是从本地csv文件创建的,工作正常。

代码语言:javascript
复制
cars = pd.read_csv(r'C:\Users\arman\OneDrive\Desktop\mtcars.csv')
cars.columns = ['car_names','mpg','cyl','disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']
df = cars[['cyl', 'wt','mpg']]
layouts = dict(title = 'Chart From Pandas DataFrame', xaxis= dict(title='x-axis'), yaxis= dict(title='y-axis'))
df.iplot(filename='cf-simple-line-chart', layout= layouts)

运行此程序时,我得到以下错误:

ValueError: the data property of a figure may only be assigned a list or tuple that contains a permutation of a subset of itself Invalid trace(s) with uid(s): set([None])

代码语言:javascript
复制
ValueErrorTraceback (most recent call last)
<ipython-input-9-9d51de7f2e8a> in <module>()
  6 cars_select.columns = ['mpg', 'disp', 'hp']
  7 
----> 8 cars_select.iplot(kind='histogram', filename='multiple-histogram-chart')
C:\Users\arman\AppData\Local\Continuum\anaconda2\lib\site-packages\cufflinks\plotlytools.pyc in _iplot(self, data, layout, filename, sharing, kind, title, xTitle, yTitle, zTitle, theme, colors, colorscale, fill, width, dash, mode, symbol, size, barmode, sortbars, bargap, bargroupgap, bins, histnorm, histfunc, orientation, boxpoints, annotations, keys, bestfit, bestfit_colors, mean, mean_colors, categories, x, y, z, text, gridcolor, zerolinecolor, margin, labels, values, secondary_y, subplots, shape, error_x, error_y, error_type, locations, lon, lat, asFrame, asDates, asFigure, asImage, dimensions, asPlot, asUrl, online, **kwargs)
899 ## Figure defintion
900         figure=Figure()
--> 901         figure['data']=data
902         figure['layout']=layout
903 
C:\Users\arman\AppData\Local\Continuum\anaconda2\lib\site-packages\plotly\basedatatypes.pyc in __setitem__(self, prop, value)
234 
235             if prop == 'data':
--> 236                 self.data = value
237             elif prop == 'layout':
238                 self.layout = value
C:\Users\arman\AppData\Local\Continuum\anaconda2\lib\site-packages\plotly\basedatatypes.pyc in __setattr__(self, prop, value)
266         if prop.startswith('_') or hasattr(self, prop):
267             # Let known properties and private properties through
--> 268             super(BaseFigure, self).__setattr__(prop, value)
269         else:
270             # Raise error on unknown public properties
C:\Users\arman\AppData\Local\Continuum\anaconda2\lib\site-packages\plotly\basedatatypes.pyc in data(self, new_data)
439                 .format(invalid_uids=invalid_uids))
440 
--> 441             raise ValueError(err_msg)
442 
443         # ### Check for duplicates in assignment ###
ValueError: The data property of a figure may only be assigned a list or tuple that contains a permutation of a subset of itself
Invalid trace(s) with uid(s): set([None])

任何帮助都将不胜感激。

编辑:我已经发布了示例数据集的图像(不确定发布csv文件的最佳格式;但如果有帮助,我从Lynda.com上的Python for Data Science Essential Training课程中获得了此文件) mtcars csv file

我还尝试用以下DataFrames创建绘图:

代码语言:javascript
复制
df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'
df.scatter_matrix(filename='cufflinks/scatter-matrix', world_readable=True)

代码语言:javascript
复制
df = cf.datagen.lines()
df.iplot(kind='scatter', filename='cufflinks/cf-simple-line')

两个示例DataFrames都会产生相同的错误。我猜这可能是袖扣的问题。我目前运行的是0.8.2版本。

EN

回答 1

Stack Overflow用户

发布于 2018-08-29 07:06:50

感谢大家的帮助。发现问题出在安装Plotly时,它安装了3.1.1版本而不是2.7.0版本,从而产生了此错误。在重新安装2.7.0版本时,我能够绘制我想要绘制的图形。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52058221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档