title: Pandas dataframe from nested dictionary
body: <p>My dictionary looks like this:</p>
  
  <pre><code>{'x': {'b': 10, 'c': 20}, 'y': {'b': '33', 'c': 44}}
  </code></pre>
  
  <p>I want to get a dataframe that looks like this:</p>
  
  <pre><code>index   col1    col2    val
  0        x       b      10
  1        x       c      20
  2        y       b      33
  3        y       c      44
  </code></pre>
  
  <p>I tried calling pandas.from_dict(), but it did not give me the desired result.
  So, what is the most elegant, practical way to achieve this?</p>
  
  <p>EDIT: In reality, my dictionary is of depth 4, so I'd like to see a solution for that case, or ideally, one that would work for arbitrary depth in a general setup.</p>
  
  <p>Here is an example of a deeper dictionary:
  <code>{'x':{'a':{'m':1, 'n':2}, 'b':{'m':10, 'n':20}}, 'y':{'a':{'m':100, 'n':200}, 'b':{'m':111, 'n':222}} }</code> The appropriate dataframe should have 8 rows.</p>
  
  <p>ANSWER:   </p>
  
  <pre><code>df = pd.DataFrame([(k1, k2, k3, k4, k5, v) for k1, k2345v in dict.items()
                             for k2, k345v in k2345v.items()
                             for k3, k45v in k345v.items()
                             for k4, k5v in k45v.items()
                             for k5, v in k5v.items()])
  </code></pre>