title: Pandas pivot and group by?
body: <p>I'm using pandas to load a .csv extract then do some transformations with the ultimate goal of exporting the data set back out to a .csv.  I have a dataframe that is structured similarly to:</p>
  
  <pre><code>col1    col2    col3        col4
  name1   Yes     string1     val1
  name2           string1     val1
  name3           string1     val1
  name2   Yes     string2     val2
  name3           string2     val2
  name4           string2     val2
  name3   Yes     string3     val3
  name4           string3     val3
  name5           string3     val3
  
  </code></pre>
  
  <p>and would like the output to appear like:</p>
  
  <pre><code>name1   name2   name3   name4   name5   col3        col4
  Yes                                     string1     val1
          Yes                             string2     val2
                  Yes                     string3     val3
  
  </code></pre>
  
  <p>I was able to use <code>.pivot()</code> to get the data in col1 and col2 from the original dataframe to appear as desired, but as far as I understand it, there's no way to include other columns with grouped values (col3 and col4 in this example) using <code>.pivot()</code>, and it appears as though <code>.pivot_table()</code> won't work for my purposes.  The remaining problem I have using <code>.pivot()</code> is that when the new index is formed, I lose the ability to join back to those other grouped columns (again, col3 and col4 here).</p>
  
  <p>Am I heading down the right path?  Or is there a better way of approaching what I'm trying to accomplish?</p>
  
  <p>Thanks in advance.</p>