2

I am trying to create a graph using Plotly off of a DataFrame as part of a Python course. The DataFrame is created from a local csv file, which is working fine.

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)

When running this, I get the following error:

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])

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])

Any help would be greatly appreciated.

Edit: I have posted an image of the sample dataset (not sure the best format for posting the csv file; but if it helps, I got this file from the course Python for Data Science Essential Training on Lynda.com) mtcars csv file

I have also tried creating plots with the following DataFrames:

df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'
df.scatter_matrix(filename='cufflinks/scatter-matrix', world_readable=True)

and

df = cf.datagen.lines()
df.iplot(kind='scatter', filename='cufflinks/cf-simple-line')

both example DataFrames produce the same error. I'm assuming this may be an issue with Cufflinks. I am currently running the 0.8.2 version.

5
  • Can you try and reproduce this error with a sample of your dataset? And if so, can you post the dataframe that produces the error? It will make it easier for us to understand your issue and answer. Commented Aug 28, 2018 at 12:52
  • I updated the question to include the file (though I'm not sure what is the best way to do this) and I've included the error message in the code format if that makes it easier to understand. I've also tried the same type of pandas object command using Plotly with different arguments (such as specifying the kind and subplots arguments) and I get the same error. Commented Aug 28, 2018 at 13:09
  • I cannot reproduce your error. Could you try and provide a minimal reproducible example? Try to copy paste what is necessary in your code, that is the libraries you import, a little piece of code to produce a sample of your dataframe, and the lines until your error. Commented Aug 28, 2018 at 13:51
  • So I've tried limiting the DataFrame to a smaller sample and using other preset DataFrames such as a randomly generated one (edited in to the initial question) and those don't seem to work. I'm guessing this may be an issue with cufflinks as it should be outputting plots directly using Pandas objects and the iplot function. However I don't know what the issue could be with cufflinks. Commented Aug 28, 2018 at 14:51
  • Hmm. You sure that you dont need to specify data and trace? Just look in the docs and see how plotly simple skeleton looks like. My thoughts, that you miss to specify data for your xaxis and yxis. You give plot the title - its nice, but plotly as I see have not any data for plot. So am suggest you to set parameter trace and fill him with data. Maybe it can helps Commented Aug 28, 2018 at 18:36

1 Answer 1

2

Thanks for everyone's help. Found out that the issue was in installing Plotly, it installed the 3.1.1 version instead of the 2.7.0, producing this error. In re-installing the 2.7.0 version, I was able to plot the graph I intended to plot.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.