0

I've looked at these pages: Nested Dictionary to MultiIndex pandas DataFrame (3 level) Pandas Dataframe from nested dictionary of pandas dataframes Dict of dicts of dicts to DataFrame

What I want to do is very similar to third example except I want to switch the index order (minor before major) and not have the outer index repeated. Here is my initial dictionary:

budget = {'January':{'income':{'work1':1982,'work2':1983},'expenses':{'rent':1500,'insurance':110}},
        'February':{'income':{'work1':1982,'work2':1983},'expenses':{'rent':1500,'insurance':110}},
        'March':{'income':{'work1':1982,'work2':1983},'expenses':{'rent':1500,'insurance':110,'other':150}},
        'April':{'income':{'work1':1982,'work2':1983},'expenses':{'rent':1500,'insurance':110}},
        'May':{'income':{'work1':1982,'work2':1983},'expenses':{'rent':1500,'insurance':110,'groceries':50}}
        }

Output from third page:enter image description here

Desired output Excel example (but want as DataFrame):enter image description here

Thanks for any help!

ZachGutz
  • 51
  • 4
  • [DataFrame.swaplevel](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.swaplevel.html) -> `df = df.swaplevel()`? – Henry Ecker Oct 24 '21 at 19:35
  • @HenryEcker Wow that was simple. I've never seen that swaplevel() function. Thank you so much! Unless I start to overcomplicate things, this should work! – ZachGutz Oct 24 '21 at 20:02

0 Answers0