![]() |
how to filter data frame dynamically with the columns - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: how to filter data frame dynamically with the columns (/thread-29238.html) |
how to filter data frame dynamically with the columns - psahay - Aug-24-2020 Hi every one I am learning python and am trying to filter a dataframe where I can create a dropdown for a column defined in dataframe and filter it dynamically . Please see the code below and i am able to create a dropdown for field id but it does not filter the values. If i hard code the (df2 = df1[(df1["id"]== 2)]). It does filter the data set. Can some one please help me and send me a sample code for filtering data in dataframe dynamically. Thanks import pandas as pd import ipywidgets as widgets dummy_data1 = { 'id': ['1', '2', '3', '4', '5'], 'Feature1': ['A', 'C', 'E', 'G', 'I'], 'Feature2': ['B', 'D', 'F', 'H', 'J']} df1 = pd.DataFrame(dummy_data1, columns = ['id', 'Feature1', 'Feature2']) print (df1) output = widgets.Output() x = dropdown_field = widgets.Dropdown(options = (df1.id)) df2 = df1[(df1["id"]== x)] input_widgets = widgets.HBox([dropdown_field]) display(input_widgets) display(output) |