Jupyter Lab ValueError: Can't clean for JSON

Really new to the Jupyter/Pandas/Plotly ecosystem. Successfully reading in dataframes and calculating some new columns with success. Trying to do a simple scatter plot with a single variable.

X Variable is DeltaTimeSeconds - pretty much just monotonically increasing value

count    28735.000000
mean     14429.311258
std       8301.268089
min          0.000000
25%       7249.500000
50%      14433.000000
75%      21616.500000
max      28800.000000
Name: DeltaTimeSeconds, dtype: float64

Y Variable is AI01 - a floating-point measured value from a piece of manufacturing equipment

count    28735.000000
mean      7613.120717
std       6526.985839
min          6.747771
25%       2126.074707
50%       3712.778809
75%      13935.562010
max      19550.572270
Name: AI01, dtype: float64

Straight from Jupyter Lab Github Page with minor tweak for my dataset

from IPython.display import display
def Plotly(data=[], layout={}):
    bundle = {}
    bundle['application/vnd.plotly.v1+json'] = {
        'data': data,
        'layout': layout,
    display(bundle, raw=True)

data = [
    {'x': df['DeltaTimeSeconds'], 'y': df['AI01'], 'type': 'scatter'}

layout = {
    'title': 'AI01',
    'xaxis': {'title': 'DeltaTime', 'showgrid': False, 'zeroline': False},
    'yaxis': {'title': 'AI01', 'showline': False}
Plotly(data, layout)

and I get this error

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\jsonutil.py in json_clean(obj)
    196     # we don't understand it, it's probably an unserializable object
--> 197     raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: 0            0
1            1

I doubled back and cleaned up some null rows from AI01 so I shouldn’t have any null data in AI01.

I’m suspecting I’m making a rookie mistake that I just can’t see right now.

Many thanks in advance for a nudge in the right direction. Once I get through this one I have a much more complex question that may actually challenge the group, I promise :slight_smile:

Hmm so this isn’t how I would do things… the JupyterLab page is pretty out of date at this point. Can you share the URL of the page you’re following so I can try to get it updated?

The most up to date/recommended way to do this today would be to first follow all the JupyterLab installation instructions here https://plot.ly/python/getting-started/#jupyterlab-support-python-35 and then to do something like

import plotly.express as px
figure = px.scatter(df, x='DeltaTimeSeconds', y='AI01')

Awesome, thanks.

Here’s the ref where I got the demo code

Will follow your link and see how it goes.


Followed instructions - broke JupyterLab but got that working again.

Used your example code - don’t get any errors but instead get nothing rendered.

Also tried the simple examples like

import plotly.graph_objects as go
fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"

and also nothing renders.

Played around with the renderers

import plotly.io as pio
Renderers configuration
    Default renderer: 'jupyterlab'
    Available renderers:
        ['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
         'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
         'cocalc', 'databricks', 'json', 'png', 'jpeg', 'jpg', 'svg',
         'pdf', 'browser', 'firefox', 'chrome', 'chromium', 'iframe',
         'iframe_connected', 'sphinx_gallery']

Were you able to install the JupyterLab extensions? They are required for figure.show() to work.

Yes I tried to follow those instructions to a T. I am wondering if I broke the install because I had conflicting plotly extensions installed maybe? If you take a look at the github link above it asks me to install an extension to render plotly. Is this complementary to your instructions or possible in conflict?

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online