title: How to convert pandas groupby result into a consolidated dictionary?
body: <p>I have created a sample dataframe using the following, and have subsequently grouped its values as seen below:</p>
  <pre><code>import pandas as pd
  
  data = {'Country': ['United States', 'United States', 'United States', 'India', 'India', 'Australia', 'Australia',
                      'Australia',
                      'Australia'],
          'State': ['New York', 'California', 'California', 'Karnataka', 'Punjab', 'Victoria', 'Victoria', 'Victoria',
                    'Victoria'],
          'Team': ['Globetrotters', 'Lakers', 'Lakers', 'Beasts', 'Steelers', 'United', 'United', 'United', 'United'],
          'Player': ['Dudley', 'James', 'Davis', 'Kumar', 'Singh', 'Smith', 'Smith', 'Smith', 'Jones'],
          'Status': ['Normal', 'NBA Legend', 'NBA', 'Normal', 'Normal', 'Normal', 'Normal', 'NBA', 'Normal']}
  
  df = pd.DataFrame(data)
  
  columns = ['Country', 'State', 'Team', 'Player', 'Status']
  groupings = df.groupby(columns).size()
  
  print(groupings)
  </code></pre>
  <p>The output of the above code snippet is as follows:</p>
  <pre><code>Country        State       Team           Player  Status    
  Australia      Victoria    United         Jones   Normal        1
                                            Smith   NBA           1
                                                    Normal        2
  India          Karnataka   Beasts         Kumar   Normal        1
                 Punjab      Steelers       Singh   Normal        1
  United States  California  Lakers         Davis   NBA           1
                                            James   NBA Legend    1
                 New York    Globetrotters  Dudley  Normal        1
  </code></pre>
  <p>I would like to convert this result into a list of dictionaries that looks like this:</p>
  <pre><code>[{'Country': 'Australia', 'State': 'Victoria', 'Team': 'United', 'Jones': 1, 'Smith': 3, 'Normal': 3, 'NBA': 1, 'Total': 4},
   {'Country': 'India', 'State': 'Karnataka', 'Team': 'Beasts', 'Kumar': 1, 'Normal': 1, 'Total': 1},
   {'Country': 'India', 'State': 'Punjab', 'Team': 'Stealers', 'Singh': 1, 'Normal': 1, 'Total': 1},
   {'Country': 'United States', 'State': 'California', 'Team': 'Lakers', 'Davis': 1, 'James': 1, 'NBA': 1,'NBA Legend': 1, 'Total': 2},
   {'Country': 'United States', 'State': 'New York', 'Team': 'Globetrotters', 'Dudley': 1, 'Normal': 1, 'Total': 1}]
  </code></pre>
  <p>Please note that in the above sample output, the combination of Country, State and Team are all unique per dictionary. Also, the Player and Status columns are no longer retained, and are instead replaced by their actual values and counts. Finally, a new Total column is added (sum of all the players/statuses per Country + State + Team combination).</p>
  <p>I know this is a bit of a complicated question, but hopefully I am clear in my explanations and requirements. Thank you for your help!</p>