title: Pandas - select column using other column value as column name
body: <p>I have a dataframe that contains a column, let's call it &quot;names&quot;. &quot;names&quot; has the name of other columns. I would like to add a new column that would have for each row the value based on the column name contained on that &quot;names&quot; column.</p>
  <p>Example:</p>
  <p>Input dataframe:
  <code>pd.DataFrame.from_dict({&quot;a&quot;: [1, 2, 3,4], &quot;b&quot;: [-1,-2,-3,-4], &quot;names&quot;:['a','b','a','b']})</code></p>
  <pre>
    a  |  b  | names |
   --- | --- | ----  |
    1  |  -1 | 'a'   |
    2  |  -2 | 'b'   |
    3  |  -3 | 'a'   |
    4  |  -4 | 'b'   |
  </pre>
  <p>Output dataframe:
  <code>pd.DataFrame.from_dict({&quot;a&quot;: [1, 2, 3,4], &quot;b&quot;: [-1,-2,-3,-4], &quot;names&quot;:['a','b','a','b'], &quot;new_col&quot;:[1,-2,3,-4]})</code></p>
  <pre>
    a  |  b  | names | new_col | 
   --- | --- | ----  | ------  |
    1  |  -1 | 'a'   |    1    |
    2  |  -2 | 'b'   |   -2    |
    3  |  -3 | 'a'   |    3    |
    4  |  -4 | 'b'   |   -4    |
  </pre>