title: How to create a data frame from a deeply nested dictionary?
body: <p>I have a nested dictionary that has 5 levels <code>masterdict = {a : {b: {c: {d : { e:  }}}}}</code> and I am trying to create a flat data frame. </p>
  
  <p>When I run the following code: </p>
  
  <pre><code>masterDF = pd.DataFrame()
  
  for a in masterdict:
     for b in masterdict[a]:
        for c in masterdict[a][b]:
           for d in masterdict[a][b][c]:
              eDF = pd.DataFrame(masterdict[a][b][c][d])
              eDF['level4'] = str(d)
              eDF['level3'] = str(c)
              eDF['level2'] = str(b)
              eDF['level1'] = str(a)
              masterDF = masterDF.append(eDF)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  PandasError                               Traceback (most recent call last)
  &lt;ipython-input-13-cc9930935c64&gt; in &lt;module&gt;()
        5       for c in masterdict[a][b]:
        6          for d in masterdict[a][b][c]:
  ----&gt; 7             eDF = pd.DataFrame(masterdict[a][b][c][d])
        8             eDF['level4'] = str(d)
        9             eDF['level3'] = str(c)
  
  C:\Anaconda\lib\site-packages\pandas\core\frame.pyc in __init__(self, data, index, columns, dtype, copy)
      275                                          copy=False)
      276             else:
  --&gt; 277                 raise PandasError('DataFrame constructor not properly called!')
      278 
      279         NDFrame.__init__(self, mgr, fastpath=True)
  
  PandasError: DataFrame constructor not properly called!
  </code></pre>
  
  <p>I am not sure if this is the right code to flatten a nested dictionary but if it is, could you please suggest what I might be doing wrong?</p>
  
  <p>Thank you.</p>