I have a dictionary like this:
my_dict = {'Key': {'Service': {'Number': 61, 'Percent': 2.54 }, 'Service2': {'Number': 42, 'Percent': 2.2 } }, 'Key2': {'Service3': {'Number': 8, 'Percent': 2.74}, 'Service2': {'Number': 52, 'Percent': 2.5 } }}
I'm trying to convert this to a pandas dataframe. I got this solution to work
pandas.concat(map(pandas.DataFrame, my_dict.itervalues()), keys=my_dict.keys()).stack().unstack(0)
However, my problem is that that I get a table where the row index is a multindex of Service & Number/Percent. Instead, I want the index to be only the different Services that come up (not a multiindex), and want the columns to be the Keys like they are now, but with 1 column section being Number and the 2nd column section being all the Keys with percent, if that makes sense. Transposing is not what I want, because I don't want the entire index to change, just the Number/Percent part. I want it to look like this, after converting it to a dataframe from the dictionary I wrote above:
Number Percent
Key Key2 Key Key2
Service 61 NaN 2.54 NaN
Service2 42 52 2.2 2.5
Service3 NaN 8 NaN 2.74
Any suggestions on this?