title: Using variable within the 'query' method of pandas dataframe
body: <p>I wanted to use external variable with the <code>query</code> method in a <code>pandas dataframe</code>. Below is my code</p>
  <pre><code>import pandas as pd
  df1 = pd.DataFrame({'col1' : ['AA', 'BB', 'CC'], 'col2' : [2,3,4], 'col3' : [10,11,12]})
  
  ii = 'BB'
  
  pd.concat([pd.DataFrame([[df1.query(&quot;col1 == @ii&quot;).reset_index(drop = True).iloc[0, 1] * jj for jj in range(0,3)], 
                  [df1.query(&quot;col1 == @ii&quot;).reset_index(drop = True).iloc[0, 2] + jj for jj in range(0,3)]]).T for ii in df1['col1'].values], axis = 1)
  </code></pre>
  <p>The result looks strange to me. I used a variable <code>ii</code> within <code>query</code> method which supposed to change based on different values of <code>col1</code>. But it appears to take only the value <code>ii = 'BB'</code> which is defined externally.</p>
  <p>Is there any explanation to this behavior? How can I change the value of <code>ii</code> within <code>query</code> method?</p>