title: Pandas & Jango - How to create a DataFrame filter from multiple user inputs without using string executable
body: <p>I am building a website where users can graph data in a dataframe and apply filters to this data to only plot information they are interested in, as shown below</p>
  <p><a href="https://i.stack.imgur.com/ch4yC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ch4yC.png" alt="enter image description here" /></a></p>
  <p>Right now I am having trouble figuring out a way to take the filters a user inputs in the fields above and using those inputs to filter the dataframe. Since the user can create an unbounded number of filters, I decided to use a for loop to build an executable string that contains all of the filters in one variable that is shown below</p>
  <pre><code>column = (value selected in &quot;Select Parameter&quot;, which corresponds to a column in the dataframe)
  boolean = (value selected in &quot;Select Condition&quot; e.g., &gt;, &lt;, &gt;= ect....
  user_input = (value user inputs into field e.g., 2019 and Diabetes)
  
  executable = 'df = df[df[' + column1 + '] ' + boolean1 + user_input1 + ' and ' + 'df[' + column2 + '] ' + boolean2 + user_input2 + ' and '.....
  exec(executable)
  </code></pre>
  <p>While this method works, it leaves my code very vulnerable to injection. Is there a better way of doing this?</p>