title: Pandas convert Dataframe to Nested Json
body: <p>My question is essentially the opposite of this one:</p>
  
  <p><a href="https://stackoverflow.com/questions/21494030/create-a-pandas-dataframe-from-deeply-nested-json">Create a Pandas DataFrame from deeply nested JSON</a></p>
  
  <p>I'm wondering if it's possible to do the reverse. Given a table like:</p>
  
  <pre><code>     Library  Level           School Major  2013 Total
  200  MS_AVERY  UGRAD  GENERAL STUDIES  GEST        5079
  201  MS_AVERY  UGRAD  GENERAL STUDIES  HIST           5
  202  MS_AVERY  UGRAD  GENERAL STUDIES  MELC           2
  203  MS_AVERY  UGRAD  GENERAL STUDIES  PHIL          10
  204  MS_AVERY  UGRAD  GENERAL STUDIES  PHYS           1
  205  MS_AVERY  UGRAD  GENERAL STUDIES  POLS          53
  </code></pre>
  
  <p>Is it possible to generate a nested dict (or JSON) like:</p>
  
  <p>dict:</p>
  
  <pre><code>{'MS_AVERY': 
      { 'UGRAD' :
          {'GENERAL STUDIES' : {'GEST' : 5}
                               {'MELC' : 2}
  
   ...
  </code></pre>