Python Forum
how to filter data frame dynamically with the columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to filter data frame dynamically with the columns
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping in pandas/multi-index data frame Aleqsie 3 607 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 1,331 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Exporting data frame to excel dyerlee91 0 1,605 Oct-05-2021, 11:34 AM
Last Post: dyerlee91
  Pandas Data frame column condition check based on length of the value aditi06 1 2,655 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Adding a new column to a Panda Data Frame rsherry8 2 2,083 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  import columns of data from local csv file CatherineKan 2 3,301 May-10-2021, 05:10 AM
Last Post: ricslato
  pandas.to_datetime: Combine data from 2 columns ju21878436312 1 2,421 Feb-20-2021, 08:25 PM
Last Post: perfringo
  grouped data frame glitter 0 1,577 Feb-02-2021, 11:22 AM
Last Post: glitter
  Can the data types be different for different columns? Robotguy 2 2,081 Aug-19-2020, 09:24 PM
Last Post: Robotguy
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,187 Aug-03-2020, 02:05 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020