title: Can someone help me convert this dataframe into a nested dictionary in Python?
body: <pre><code>index      print_type_solid      print_type_floral  cluster
       A           10                     10            2
       B           20                     20            2
       A           10                     10            3
       B           20                     20            3
       C           25                     30            3
  
  </code></pre>
  <p>Can someone help me convert the above dataframe into the following nested dictionary where the cluster becomes the main key and and the print_type_x as key and then the values as shown in the expected output below ?</p>
  <pre><code> {  
   &quot;2&quot; :{
          &quot;print_type_solid&quot; : {
            &quot;A&quot;: 10,
            &quot;B&quot;: 20
                              },
          &quot;print_type_floral&quot; : {
              &quot;A&quot;: 10,
              &quot;B&quot;: 20
                               }
          },
  
  &quot;3&quot; :{
          &quot;print_type_solid&quot; : {
            &quot;A&quot;: 10,
            &quot;B&quot;: 20,
            &quot;C&quot;: 25,
                              },
          &quot;print_type_floral&quot; : {
              &quot;A&quot;: 10,
              &quot;B&quot;: 20,
              &quot;C&quot;: 30,
                               }
          }
  
  }
  </code></pre>