I have converted a continuous variable, x, into interval. And i have a y variable with numerical values. The dataframe is:
data = {'x':[(-0.001, 7.0], (7.0, 19.0], (19.0, 97.0], (97.0, 817.0]],
'y':[769.0, 810.0,757.0,652.0]}
# Create DataFrame
df = pd.DataFrame(data)
df
The data types for both these variables are float64. Furthermore, the description for variable 'x' is given as:
Name: x, dtype: category
Categories (4, interval[float64]): [(-0.001, 7.0] < (7.0, 19.0] < (19.0, 97.0] < (97.0, 817.0]]
Now, i'm using plotly to graph the relationship between these two variables:
# figure
plot_data = [
go.Scatter(
x = df['x'],
y = df['y'])]
plot_layout = go.Layout(title=' Relationship between x and y')
fig = go.Figure(data=plot_data, layout=plot_layout)
pyoff.iplot(fig)
But the error shown is:
TypeError: Object of type Interval is not JSON serializable
So, as far as I understood, the variable 'x' is given as interval in a format which plotly is unable to identify. How to fix this? Is there any example known to you where one can use plotly to plot interval variable?
Intervalobject is not JSON serializable - i.e. JSON lib doesn't know how to convert it to JSON format. You would need to implement a method for encoding theIntervalon your side and decoding it onplotlyback to interval or some adequate representation. A workaround might be to list the interval with enough granularity i.e.(1,100]to[1.0001, 1.01, 2, 3, ..., 100]which should be OK with json.pd.qcutto divide it into four groups