title: Nested JSON in customised format from pandas Dataframe, with added label
body: <p>Dataframe</p>
  <pre><code>df = {&quot;UNIT&quot;:[&quot;UNIT1&quot;,&quot;UNIT1&quot;,&quot;UNIT2&quot;,&quot;UNIT2&quot;],
  &quot;PROJECT&quot;:[&quot;A&quot;,&quot;A&quot;,&quot;C&quot;,&quot;C&quot;],
  &quot;TEAM&quot;:[1,2,1,2],
  &quot;NAME&quot;:[&quot;FANNY&quot;, &quot;KATY&quot;, &quot;PERCY&quot;, &quot;PETER&quot;],
  &quot;ID&quot;:[123,234,333,222]}
  data = pd.DataFrame(df)
  
      UNIT PROJECT  TEAM   NAME   ID
  0  UNIT1       A     1  FANNY  123
  1  UNIT1       A     2   KATY  234
  2  UNIT2       C     1  PERCY  333
  3  UNIT2       C     2  PETER  222
  </code></pre>
  <p>Expected output</p>
  <pre><code>[
      {
          &quot;UNIT&quot;: &quot;UNIT1&quot;,
          &quot;PROJECT&quot;: &quot;A&quot;,
          &quot;TEAM_DETAIL&quot;: [
              {
                  &quot;TEAM&quot;: 1,
                  &quot;MEMBER&quot;: [
                      {
                          &quot;NAME&quot;: &quot;FANNY&quot;,
                          &quot;ID&quot;: 123
                      }
                  ]
              },
              {
                  &quot;TEAM&quot;: &quot;TEAM 2&quot;,
                  &quot;MEMBER&quot;: [
                      {
                          &quot;NAME&quot;: &quot;KATY&quot;,
                          &quot;ID&quot;: 234
                      }
                  ]
              }
          ]
      },
      {
          &quot;UNIT&quot;: &quot;UNIT2&quot;,
          &quot;PROJECT&quot;: &quot;C&quot;,
          &quot;TEAM_DETAIL&quot;: [
              {
                  &quot;TEAM&quot;: 1,
                  &quot;MEMBER&quot;: [
                      {
                          &quot;NAME&quot;: &quot;PERCY&quot;,
                          &quot;ID&quot;: 333
                      }
                  ]
              },
              {
                  &quot;TEAM&quot;: &quot;TEAM 2&quot;,
                  &quot;MEMBER&quot;: [
                      {
                          &quot;NAME&quot;: &quot;PETER&quot;,
                          &quot;ID&quot;: 222
                      }
                  ]
              }
          ]
      }
  ]
  </code></pre>
  <p>In this situation I would like to group the data by <code>TEAM</code> and hence showing each of the member details in each team.
  Without adding customised label eg.<code>TEAM_DETAIL</code> and <code>MEMBER</code>,
  it can be easily achieved by using <code>.to_dict()</code>
  However, I have no idea how to add a label on each level.</p>