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?
you only need to cast the column with ".astype('str')"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With