title: Pandas - unstack column values into new columns
body: <p>I have a large dataframe and I am storing a lot of redundant values that are making it hard to handle my data. I have a dataframe of the form:</p>
  
  <pre><code>import pandas as pd
  
  df = pd.DataFrame([["a","g","n1","y1"], ["a","g","n2","y2"], ["b","h","n1","y3"], ["b","h","n2","y4"]], columns=["meta1", "meta2", "name", "data"])
  
  &gt;&gt;&gt; df
  
    meta1 meta2 name data
      a     g   n1   y1
      a     g   n2   y2
      b     h   n1   y3
      b     h   n2   y4
  </code></pre>
  
  <p>where I have the names of the new columns I would like in <code>name</code> and the respective data in <code>data</code>.</p>
  
  <p>I would like to produce a dataframe of the form:</p>
  
  <pre><code>df = pd.DataFrame([["a","g","y1","y2"], ["b","h","y3","y4"]], columns=["meta1", "meta2", "n1", "n2"])
  
  &gt;&gt;&gt; df
  
  meta1 meta2  n1  n2
    a     g  y1  y2
    b     h  y3  y4
  </code></pre>
  
  <p>The columns called <code>meta</code> are around 15+ other columns that contain most of the data, and I don't think are particularly well suited to for indexing. The idea is that I have a lot of repeated/redundant data stored in <code>meta</code> at the moment and I would like to produce the more compact dataframe presented.</p>
  
  <p>I have found some similar Qs but can't pinpoint what sort of operations I need to do: pivot, re-index, stack or unstack, etc.?</p>
  
  <p>PS - the original index values are unimportant for my purposes.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><strong>Question I think is related:</strong></p>
  
  <p>I think the following Q is related to what I am trying to do, but I can't see how to apply it, as I don't want to produce more indexes.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/22665261/python-pandas-how-to-unstack-a-pivot-table-with-two-values-with-each-value-beco">Python Pandas- how to unstack a pivot table with two values with each value becoming a new column?</a></li>
  </ul>