title: How to convert pandas dataframe to nested dictionary
body: <p>I am running Python 3.6 and Pandas 0.19.2 and have a DataFrame which looks as follows: </p>
  
  <pre><code>Name      Chain        Food       Healthy  
  
  George    McDonalds    burger     False
  George    KFC          chicken    False
  John      Wendys       burger     False
  John      McDonalds    salad      True
  </code></pre>
  
  <p>I want to transform this dataframe into a dict which looks as follows: </p>
  
  <pre><code>health_data = {'George': {'McDonalds': {'Food': 'burger', 'Healthy':False},
                            'KFC':       {'Food': 'chicken', 'Healthy':False}},
                 'John':   {'Wendys':    {'Food': 'burger', 'Healthy':False},
                            'McDonalds': {'Food': 'salad', 'Healthy': True}}}
  </code></pre>
  
  <p>My thoughts so far are: </p>
  
  <ol>
  <li>Use <code>df.groupby</code> to group the names column</li>
  <li>Use <code>df.to_dict()</code> to transform the dataframe into a dictionary along the lines of:
      <code>health_data = input_data.set_index('Chain').T.to_dict()</code></li>
  </ol>
  
  <p>Thoughts? Thanks up front for the help.  </p>