Jitesh Malli
Jitesh Malli

Reputation: 33

Print Nested Dictionary Keys and values in a tabular format

I would like to print my nested dictionary into a tabular format which would somehow look like this:

**ID**      **Count**    **Time**   **OutCount**  **OutTime**

  262          725        15:29          725         15:29

and so on .....

My nested dictionary is:

{'262': {'count': 725,'time': '15:29','outcount': 725,'outtime': '15:29'},
'343': {'count': 699,'time': '15:29','outcount': 699,'outtime': '15:29'},
'809': {'count': 695,'time': '15:29','outcount': 695,'outtime': '15:29'}

Upvotes: 2

Views: 86

Answers (1)

Dishin H Goyani
Dishin H Goyani

Reputation: 7693

Use pd.DataFrame.from_dict

pd.DataFrame.from_dict(d, orient='index')
     count   time  outcount outtime
262    725  15:29       725   15:29
343    699  15:29       699   15:29
809    695  15:29       695   15:29

or with reset_index

pd.DataFrame.from_dict(d, orient='index').reset_index()
  index  count   time  outcount outtime
0   262    725  15:29       725   15:29
1   343    699  15:29       699   15:29
2   809    695  15:29       695   15:29

Upvotes: 5

Related Questions