简体   繁体   English

以表格格式打印嵌套字典键和值

[英]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'}

Use pd.DataFrame.from_dict使用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或使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM