title: Python - Lookup value from different columns dynamically
body: <p>I have the following dataframes.</p>
  <pre><code>Name   |  Data
  A         foo
  A         bar
  B         foo
  B         bar
  C         foo
  C         bar
  C         cat
  
  
  
  Name   |  foo  |  bar  |  cat
  A         1        2       3
  B         4        5       6
  C         7        8       9
  </code></pre>
  <p>I need to lookup the values present in the 2nd dataframe and create a dataframe like this</p>
  <pre><code>Name   |  Data  |  Value
  A         foo      1
  A         bar      2
  B         foo      4
  B         bar      5
  C         foo      7
  C         bar      8
  C         cat      9
  </code></pre>
  <p>I tried looping over df1 and parsing df2 like df2[df2['Name']=='A']['foo'], this works but it takes forever to complete. I am new to python and any help to reduce the runtime would be appreciated.</p>