title: Create a variable in a Pandas dataframe based on information in the dataframe
body: <p>I have a dataframe organized in the following way</p>
  
  <pre><code>    var1   var2   var3   var4
  0   A      23     B      7
  1   B      13     C      4
  2   C      12     A      11
  3   A      5      C      15
  </code></pre>
  
  <p>I now want to create a new variable (column), var5, which takes the value of var2 if var1 == A and the value of var4 if var3 == A. For simplicity, var1 and var3 can never both have the value A. If neither var1 or var3 takes value A, then I want NaN. That is, the outcome in this example would be:</p>
  
  <pre><code>    var1   var2   var3   var4  var5
  0   A      23     B      7     23
  1   B      13     C      4     NaN
  2   C      12     A      11    11
  3   A      5      C      15    5
  </code></pre>
  
  <p>How can this be achieved?</p>