I'm busy with programming an interactive graph where the values in the graph are chosen based on columnvalues from a dataframe. So, I want to make a graph of values in column x where only the values are chosen which fullfil several conditions from another columns in the dataframe. I have the following dataframe (data): Dataframe
data = pd.DataFrame([[3,'VW-b','1 R- R',119.080,'TS',13.56],
[3,'VW-b','1 R- R',119.090,'RS',18.56],
[3,'VW-b','1 R- R',119.100,'TS',12.85],
[3,'VW-b','1 R- R',119.110,'TS',9.56],
[3,'VW-b','1 R- R',119.120,'RS',8.86],
[3,'VW-b','1 R- R',119.130,'TS',13.56],
[3,'VW-b','1 R- R',119.140,'TS',19.56],
[3,'VW-b','1 R- R',119.150,'TS',14.56],
[3,'HRL','1 R- R',159.080,'RS',13.56],
[3,'VW-c','1 R- R',19.080,'RS',13.56],
[3,'VW-s','1 R- R',254.080,'TS',13.56],
[3,'VW-b','1 R- R',25.020,'TS',13.56],
[3,'VW-b','1 R- R',25.030,'TS',16.56]],
columns=['IGO', 'Baan','Strook','Km','Spoor','IDK1-2'])
My imports are:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets
from ipywidgets import interact
from ipywidgets import interactive
from IPython.display import display
%matplotlib inline
I wrote the following code:
def choice(igo, baan, strook, spoor, kmv, kmt):
Igo = data['IGO'] == igo
Baan = data['Baan'] == baan
Strook = data['Strook'] == strook
Spoor = data['Spoor'] == spoor
Kmv = data['Km'] == kmv
Kmt = data['Km'] == kmt
plt.plot(data['IDK1-2'])
plt.xlim(kmv,kmt)
w = interactive(choice,
igo=widgets.Dropdown(options=data['IGO'].unique(),description='IGO'),
baan=widgets.Dropdown(options=data['Baan'].loc[data['IGO'] == igo].unique(),description='Baan'),
strook=widgets.Dropdown(options=data['Strook'].loc[data['Baan'] == baan].unique(),description='Strook'),
spoor=widgets.RadioButtons(options=data['Spoor'].unique(),value='TS',description='Spoor'),
kmv=widgets.Dropdown(options=data['Km'].unique(),description='Van km'),
kmt=widgets.Dropdown(options=data['Km'].unique(),description='Tot km'))
display(w)
How can I make the code in such a way that I can choose first the IGO, than the baan (available choices based on IGO) etc?