I have two DataFrames:
import numpy as np
import pandas as pd
import ipywidgets as widgets
import seaborn as sns
df = pd.DataFrame(np.random.rand(6,2), index=['Nr. 1', 'Nr. 2', 'Nr. 3', 'Nr. 4', 'Nr. 5', 'Nr. 6'], columns=['A', 'B', 'C', 'D'])
df2 = pd.DataFrame(np.array([[1, 2, 3, 4]]), columns=['a', 'b', 'c', 'd'])
I want to make an interactive plot where I can choose the row of the DataFrame by a dropdown of the index of df
.
This is my approach:
Index= df.index.tolist()
Nr = widgets.Dropdown(options=Nr, value=Nr[0], description='Number:', disabled=False)
button = widgets.Button(description='Plot', disabled = False, button_style='', tooltip = 'Plotting', icon='check')
out = widgets.Output(layout={'border': '1px solid black'})
box = widgets.VBox([Nr, button])
def on_button_clicked(b):
with out:
ax = sns.regplot(x=df_2[0], y=df.loc[[Nr]])
button.on_click(on_button_clicked, False)
display(box)
However, I get this error: 'None of [Index([Dropdown(description='Nr:', index = 4, options=('Nr. 1', 'Nr. 2', 'Nr. 3', 'Nr. 4'), value = 'Nr. 1')], dtype = 'object', name='Nr')] are in the [index]'
What am I missing?