title: How to convert string output of a function into an input or a runnable shell command?
body: <p>For example I use this code to get a value for mask</p>
  <pre><code>def get_rule(path, column_names):
      mask = ''
      for index, node in enumerate(path):
          #We check if we are not in the leaf
          if index!=len(path)-1:
              # Do we go under or over the threshold ?
              if (children_left[node] == path[index+1]):
                  mask += &quot;(df['{}']&lt;= {}) \t &quot;.format(column_names[feature[node]], threshold[node])
              else:
                  mask += &quot;(df['{}']&gt; {}) \t &quot;.format(column_names[feature[node]], threshold[node])
      # We insert the &amp; at the right places
      mask = mask.replace(&quot;\t&quot;, &quot;&amp;&quot;, mask.count(&quot;\t&quot;) - 1)
      mask = mask.replace(&quot;\t&quot;, &quot;&quot;)
      return mask
  </code></pre>
  <p>Once we run the function we get something like this:</p>
  <pre><code>&gt;&gt;&gt; output = get_rule(...)
  &gt;&gt;&gt; output
  
  &quot;(df['A']&lt;= 0.12) &amp; (df['B']&gt; 0.07) &amp; (df['C']&lt;= 0.24) &amp; (df['D']&lt;= 4.0) &amp; (df['A']&gt; 0.92)&quot;
  </code></pre>
  <p>The output is in the form of a string and can therefore not be used as an input value.
  For example:</p>
  <pre><code>&gt;&gt;&gt; df[output] 
  </code></pre>
  <p>will give the error:</p>
  <pre><code>KeyError: &quot;(df['A']&lt;= 0.12) &amp; (df['B']&gt; 0.07) &amp; (df['C']&lt;= 0.24) &amp; (df['D']&lt;= 4.0) &amp; (df['A']&gt; 0.92)&quot;
  </code></pre>
  <p>My end goal is to use the output from the <code>get_rule</code> function directly into <code>df[ ]</code> to be able to find the region in the df, which I can else find by simply typing in this:</p>
  <pre><code>df[(df['A']&lt;= 0.12) &amp; (df['B']&gt; 0.07) &amp; (df['C']&lt;= 0.24) &amp; (df['D']&lt;= 4.0) &amp; (df['A']&gt; 0.92)]
  </code></pre>