title: Transforming multiindex df into sorted xlsx in python
body: <p>long-time reader, first-time poster. I've been doing some time tracking for two projects, grouped the data by project and date using pandas, and would like to fill it into an existing Excel template for a client that is sorted by date (y-axis) and project (x-axis). But I'm stumped. I've been struggling to convert the multi-index dataframe into a sorted xlsx file.</p>
  <p>Example data I want to sort</p>
  <pre><code>|Date       |  Project                  | Hours   |  
  |-----------|---------------------------|---------| 
  |2022-05-09 |Project 1                  |     5.50| 
  |2022-05-09 |Project 1                  |     3.75| 
  |2022-05-11 |Project 2                  |     1.50| 
  |2022-05-11 |Project 2                  |     4.75| 
  etc.
  </code></pre>
  <p>Desired template</p>
  <pre><code>|Date       |Project 1|Project 2| 
  |-----------|---------|---------| 
  |2022-05-09 |      5.5|     3.75| 
  |2022-05-11 |     4.75|      1.5| 
  etc...
  </code></pre>
  <p>So far I've tried a very basic iteration using openpyxl that has inserted the dates, but I can't figure out how to</p>
  <p>a) rearrange the data in pandas so I can simply insert it or</p>
  <p>b) how to write conditionally in openpyxl for a given date and project</p>
  <pre><code># code grouping dates and projects
  df = df.groupby([&quot;Date&quot;, &quot;Project&quot;]).sum(&quot;Hours&quot;)
  
  r = 10 # below the template headers and where I would start inserting time tracked
  for date in df.index:
          sheet.cell(row=r, column=1).value = date
          r+=1
  </code></pre>
  <p>I've trawled StackOverflow for answers but am coming up empty. Thanks for any help you can provide.</p>