【发布时间】:2018-07-07 03:10:20
【问题描述】:
我有一个想要转换为数据框的列表。 我在一个名为 data 的变量中有大约 30000 个列表。如何将其转换为具有列属性、产品 ID、描述、客户 ID 和国家/地区的数据框。我希望将元素属性转换为数据框
data[0]
Out[16]:
{'event': 'Product',
'properties': {'invoice_no': '44',
'product_id': '67',
'description': 'cloth',
'customer_id': 55,
'country': 'US'}}
data[1]
Out[17]:
{'event': 'Product',
'properties': {'invoice_no': '55',
'product_id': '66',
'description': 'shoe',
'customer_id': 23,
'country': 'China'}}
试过了,
new = pd.DataFrame.from_dict(data)
但它只给出了两列,例如“事件”和“属性”。我希望属性形成一个数据框
【问题讨论】:
标签: python python-3.x list dictionary dataframe