0

I have the following nested dictionary and I would like to convert it to a dataframe.

Nested Dictionary

The first two columns will be the keys of the first dictionary and the third column will be the nested dictionary.

The first two columns of the dataframe

Any suggestions? Thanks a lot in advance!

buczek
  • 2,011
  • 7
  • 29
  • 40
morfara
  • 190
  • 3
  • 16
  • 3
    Please dont post code as images. post the code. What have you tried? – Merlin Jun 13 '16 at 21:26
  • Thanks a lot for your editing. – morfara Jun 13 '16 at 21:29
  • 1
    It would be much easier to help you if you would provided a sample data set of your `sample_inv` DF (5-7 rows in __text__ format), explained what do you want to do and provided a desired result set. [How to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – MaxU - stand with Ukraine Jun 13 '16 at 21:44

1 Answers1

0

That's not the greatest input data, but if you're confident that the structure of the dictionary won't change, you could try something like the below:

DataFrame([
        [x[0] for x in nested_dict.keys()],
        [x[1] for x in nested_dict.keys()],
        [x for x in nested_dict.values()],
    ]).T

This should give you a DataFrame to your specs.

    0           1   2
0   timestamp4  324 {326: 3}
1   timestamp3  323 {325: 2}
2   timestamp   321 {321: 0}
3   timestamp2  322 {323: 1}
Moe Chughtai
  • 384
  • 2
  • 13