从字典向df添加许多行

时间:2019-01-13 16:24:58

标签: python pandas dictionary dataframe

我有一个简单的空数据框。

import pandas as pd
data_table = pd.DataFrame(columns=['ID', 'Name', 'Description'])

现在我读了一个json文件,并用它创建字典列表。
该列表中有成千上万的字典,看起来像这样

{'id':'1', 'name':'some_name', 'description': 'some description'}
{'id':'2', 'name':'other_name', 'description': 'other description'}

我尝试将所有这些字典推送到我的data_table变量中,但是通过所有尝试,所有形状或索引都被弄乱了。

1 个答案:

答案 0 :(得分:0)

根据您的描述dict中的所有list

youdf=pd.concat([pd.Series(x) for x in l],1).T
youdf
         description id        name
0   some description  1   some_name
1  other description  2  other_name 

数据输入

l=[{'id':'1', 'name':'some_name', 'description': 'some description'},
{'id':'2', 'name':'other_name', 'description': 'other description'}]
相关问题