Print a dictionary into a table

前端 未结 6 1814
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 06:46

I have a dictionary:

dic={\'Tim\':3, \'Kate\':2}

I would like to output it as:

Name Age
Tim 3
Kate 2

Is i

6条回答
  •  忘掉有多难
    2020-12-18 07:44

    You could use pandas.

    In [15]: import pandas as pd
    
    In [16]: df = pd.DataFrame({'Tim':3, 'Kate':2}.items(), columns=["name", "age"]) 
    
    In [17]: df
    Out[17]: 
       name  age
    0   Tim    3
    1  Kate    2
    

提交回复
热议问题