getting key error on using ipywidgets in jupyter notebook?

  ipywidgets, jupyter, python

My dataset contains COURSEID, TOPICID, CHAPTERID and SUBJECTID and all of them are natural numbers AND i want to draw some visualisations based on the values selected using dropdown, and i want the update the dropdown of new each of them based on the previous value selected

My code

from IPython.display import *
import ipywidgets as widgets
from ipywidgets import *

subject = Dropdown(options=df_new.SUBJECTID.unique().tolist())
course = Dropdown()
chapter = Dropdown()
topic = Dropdown()

def update1(*args):
    course.options = df_new[df_new[subject.value]].COURSEID.unique().tolist()
subject.observe(update1)


def update2(*args):
    chapter.options = df_new[df_new[course.value]].CHAPTERID.unique().tolist()
course.observe(update2)


def update3(*args):
    topic.options = df_new[df_new[chapter.value]].TOPICID.unique().tolist()
chapter.observe(update3)

display(subject, course, chapter, topic)

I am trying to do something like this default value of subject in the dropdown is 1 but when i execute the code i am getting key error as 1 no matter what value i choose

Needs help in knowing the error and if this is not the right way then how can i achieve these results

Source: Python Questions

LEAVE A COMMENT