title: How can I transform a multi-index pivot table to a nested list including part of the index?
body: <p><strong>Update:</strong> I really tried to have my example representative, turns out it wasn't. I updated the question as the spirit is the same, just a little more complicated.</p>
  <hr />
  <p>I'm working with a big Pandas dataset that I want to extract data from for plotting. This small example should illustrate it:</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  df = pd.DataFrame({'Name': pd.Categorical(['Carl', 'Carl', 'Carl', 'Tina', 'Tina', 'Tina',
                                             'Carl', 'Carl', 'Tina', 'Tina', 'Carl', 'Carl'] * 2),
                     'DayOfYear': [51, 20, 20, 1, 70, 140, 77, 190, 210, 365, 260, 333] * 2,
                     'Type': pd.Categorical(['Weight'] * 12 + ['Height'] * 12),
                     'Number': [60.3, 61.0, 59.8, 77.1, 74.0, 73.4, 58.2, 60.6, 73.6, 75.0, 59.7, 60.5,
                                172.3, 172.3, 172.3, 165.9, 165.9, 165.9,
                                172.3, 172.3, 165.9, 165.9, 172.3, 172.3],
                    })
  </code></pre>
  <p>I started with grouping but changed to pivot tables as the workflow seems easier—should be the same, right? I tried many things and so far this got me closest to my goal:</p>
  <pre class="lang-py prettyprint-override"><code>p = pd.pivot_table(df, index=['Name', 'DayOfYear'], values='Number', columns='Type')
  </code></pre>
  <p><a href="https://i.stack.imgur.com/RKxHR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RKxHR.png" alt="the outcome of pivoting" /></a></p>
  <p>For plotting, the remaining part would be transforming that to:</p>
  <pre class="lang-py prettyprint-override"><code>what_bqplot_needs_x = [
          [20, 51, 77, 190, 260, 333],
          [1, 70, 140, 210, 365],
          [20, 51, 77, 190, 260, 333],
          [1, 70, 140, 210, 365],
  ]
  what_bqplot_needs_y = [
          [60.4, 60.3, 58.2, 60.6, 59.7, 60.5],
          [77.1, 74.0, 73.4, 73.6, 75.0],
          [172.3] * 6,
          [165.9] * 5,
  ]
  </code></pre>
  <p>I don't seem to grasp/get along with Pandas’ <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html" rel="nofollow noreferrer">MultiIndex</a> and I really would like to understand how to massage a <code>DataFrame</code> to get there.</p>
  <p>It doesn't have to be a list of lists, a <code>ndarray</code> array would also do.</p>
  <hr />
  <p>I tried adapting <a href="https://stackoverflow.com/a/63030985/581002">jezrael’s answer</a>, but the very first <code>.reset_index(level=1)</code> already crashes with:</p>
  <pre><code>TypeError: cannot insert an item into a CategoricalIndex that is not already an existing category
  </code></pre>