Hi,
I am trying to use dropdown (multiple = True) to filter my pandas dataframe ( selecting only those columns). This is what I have tried so far.
to get the column names I use all_columns = df.columns.unique()
these two divs are the dropdowns I am using
available_indicators = []
for i in df.columns.unique() :
str(available_indicators.append({'label':i,'value':(i)}))
html.Div(className='four columns', children= drc.NamedDropdown(name='Select Features ',
id='feature_columns',
options = available_indicators,
multi=True,
value=df.columns[0],
className="dcc_control"
)),
html.Div(className='four columns', children= drc.NamedDropdown(name='Target features',
id='target_columns',
options = available_indicators,
multi=True,
value=df.columns[-1],
className="dcc_control"
),
),
my callback looks something like this
@app.callback(Output('graph-display', 'figure'),
[Input('feature_columns', 'value'),
Input('target_columns', 'value')])
def update_graph( feature_columns, target_columns):
X = feature_df(df, feature_columns)
y = feature_df(df, target_columns)
where feature_df
and target_df
are defined as:
def feature_df(df, feature_columns):
X = df[feature_columns]
return X
def target_df(df, target_columns):
y = df[target_columns]
return y
I am not sure where I made a mistake. For now, the filtering doesn’t work and pandas throw a KeyError. This means I am looking at different column names. I am not sure where I messed the column names.