title: How to filter dataframe based on user input using streamlit and python
body: <p>I have a datafarme that includes 3 columns  i want to allow the user to filter the result based on the user input  where the user can select which column to filter using a checkbox.</p>
  <p>The problem is that if the user doesn't check the 2 checkbox it return the below error :</p>
  <blockquote>
  <p>df_result_search = df[df['age']==(age_search)]</p>
  </blockquote>
  <blockquote>
  <p>NameError: name 'age_search' is not defined</p>
  </blockquote>
  <p>and if the user check all the checkbox and enter the values it return a wrong record while it takes only one value and filter based on it.</p>
  <h1>code:</h1>
  <pre><code>
  import streamlit as st 
  import pandas as pd
  
  data = {'name':['Tom', 'nick', 'krish', 'jack','Tom'],
          'nickname':['jack','krish','karim','joe','joe'],
          'age':[20, 18, 19, 18,22]}
   
  df = pd.DataFrame(data)
  df_result_search = pd.DataFrame() 
  
  
  searchcheckbox_name_nickname = st.checkbox(&quot;Name or Nickname &quot;,value = False,key=1)
  searchcheckbox_age = st.checkbox(&quot;age&quot;,value = False,key=2)
  
  if searchcheckbox_name_nickname:
      name_search = st.text_input(&quot;name&quot;)
      nickname_search = st.text_input(&quot;nickname&quot;)
  if searchcheckbox_age:   
      age_search = st.number_input(&quot;age&quot;,min_value=0)
  if st.button(&quot;search&quot;):
      df_result_search = df[df['name'].str.contains(name_search,case=False, na=False)]
      df_result_search = df[df['nickname'].str.contains(nickname_search,case=False, na=False)]
      
      df_result_search = df[df['age']==(age_search)]
                      
      st.write(&quot;{} Records &quot;.format(str(df_result_search.shape[0])))
      st.dataframe(df_result_search)
  </code></pre>