title: any efficient way to cycle through columns with its value list for conditional filtering in pandas?
body: <p>I am trying to filter the dataframe conditionally where I intend to cycle through the columns and its values list for conditional filtering but the resulted dataframe was not filtered correctly. I used a known filtering approach for pandas dataframe on <code>SO</code> such as <a href="https://stackoverflow.com/questions/53441783/pandas-conditional-filter">post 1</a>, <a href="https://stackoverflow.com/questions/44608005/conditional-filtering-of-pandas-data-frame">post2</a> and I want to parameterize these data selection processes in the function but cycle through the columns with value list is not working correctly. Any possible idea to overcome this issue? any thought?</p>
  
  <p><strong>minimal reproducible example</strong>:</p>
  
  <p>here is the <a href="https://gist.github.com/julaiti/851b7f1814e7f3f5a658bce8441e0b8d" rel="nofollow noreferrer">minimal reproducible example on gist</a> that I used in my attempt.</p>
  
  <p><strong>my attempt</strong>:</p>
  
  <p>I tried this approach and it worked pretty good but I want to parameterize in the function.</p>
  
  <pre><code>import pandas as pd
  
  df = pd.read_csv('minimal_df.csv', encoding='utf-8')
  df= df[(df['meat_type']=='Beef') &amp; (df['trade_type']=='E') &amp; (df['origin']=='US') &amp; (df['date'] &gt;'2014-01-01') &amp; (df['date'] &lt;'2019-01-01')]
  </code></pre>
  
  <p>as I said, I want to wrap up a data filtering function so I may do something like this:</p>
  
  <pre><code>def data_filter(df, colList, vaList, startDate, endDate):
      for col in colList:
          for val in vaList:
              masker = df[df[col]==val]
              masker.reset_index(drop=True)
              masker = masker.loc[(masker['date']&gt; startDate) &amp; (masker['date'] &lt; endDate)]
      return masker
  
  columns = ['meat_type', 'temperature','origin']
  values = ['Beef', 'Frozen','US']
  dat_filter(df=df, colList=columns, vaList=values, startDate='2013-12-31', endDate='2019-01-01')
  </code></pre>
  
  <p>but such an attempt doesn't work for me because resulted filtered dataframe wasn't filtered actually. Any idea to make this work correctly? </p>
  
  <p>How can I make my function even more efficient such as instead of using array as parameter is there any better way to pass parameter to the function so we can select multiple columns with value list? any thoughts? Thanks</p>