【发布时间】:2018-10-10 21:48:44
【问题描述】:
我试图寻找解决方案,但我无法得到 1。我从 python 中的 api 得到以下输出。
insights = [ <Insights> {
"account_id": "1234",
"actions": [
{
"action_type": "add_to_cart",
"value": "8"
},
{
"action_type": "purchase",
"value": "2"
}
],
"cust_id": "xyz123",
"cust_name": "xyz",
}, <Insights> {
"account_id": "1234",
"cust_id": "pqr123",
"cust_name": "pqr",
}, <Insights> {
"account_id": "1234",
"actions": [
{
"action_type": "purchase",
"value": "45"
}
],
"cust_id": "abc123",
"cust_name": "abc",
}
]
我想要这样的数据框
- account_id add_to_cart purchase cust_id cust_name
- 1234 8 2 xyz123 xyz
- 1234 pqr123 pqr
- 1234 45 abc123 abc
当我使用下面的
> insights_1 = [x for x in insights]
> df = pd.DataFrame(insights_1)
我得到以下内容
- account_id actions cust_id cust_name
- 1234 [{'value': '8', 'action_type': 'add_to_cart'},{'value': '2', 'action_type': 'purchase'}] xyz123 xyz
- 1234 NaN pqr123 pqr
- 1234 [{'value': '45', 'action_type': 'purchase'}] abc123 abc
我该如何继续?
【问题讨论】:
-
很抱歉问这个问题,
<insights>是什么? -
调用API时输出是这样显示的。
标签: python pandas dictionary dataframe