title: Dynamically evaluate an expression from a formula in Pandas
body: <p>I would like to perform arithmetic on one or more dataframes columns using <code>pd.eval</code>. Specifically, I would like to port the following code that evaluates a formula:</p>
  <pre><code>x = 5
  df2['D'] = df1['A'] + (df1['B'] * x)
  </code></pre>
  <p>...to code using <code>pd.eval</code>. The reason for using <code>pd.eval</code> is that I would like to automate many workflows, so creating them dynamically will be useful to me.</p>
  <p>My two input DataFrames are:</p>
  <pre><code>import pandas as pd
  import numpy as np
  
  np.random.seed(0)
  df1 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list('ABCD'))
  df2 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list('ABCD'))
  
  df1
     A  B  C  D
  0  5  0  3  3
  1  7  9  3  5
  2  2  4  7  6
  3  8  8  1  6
  4  7  7  8  1
  
  df2
     A  B  C  D
  0  5  9  8  9
  1  4  3  0  3
  2  5  0  2  3
  3  8  1  3  3
  4  3  7  0  1
  </code></pre>
  <p>I am trying to better understand <code>pd.eval</code>'s <code>engine</code> and <code>parser</code> arguments to determine how best to solve my problem. I have gone through <a href="https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.eval.html" rel="noreferrer">the documentation</a>, but the difference was not made clear to me.</p>
  <ol>
  <li>What arguments should be used to ensure my code is working at the maximum performance?</li>
  <li>Is there a way to assign the result of the expression back to <code>df2</code>?</li>
  <li>Also, to make things more complicated, how do I pass <code>x</code> as an argument inside the string expression?</li>
  </ol>