下面是JSON:
{
"data": [
{
"gid": "1203715497540179",
"completed": false,
"custom_fields": [
{
"gid": "1203887422469746",
"enabled": true,
"name": "Inputs",
"description": "",
"display_value": null,
"resource_subtype": "text",
"resource_type": "custom_field",
"text_value": null,
"type": "text"
},
{
"gid": "1126427465960522",
"enabled": false,
"name": "T-Minus",
"description": "",
"display_value": "54",
"resource_subtype": "text",
"resource_type": "custom_field",
"text_value": "54",
"type": "text"
}
],
"due_on": "2023-01-25",
"name": "General Information"
}
]
}
我想用它来构建下面的pandas数据框。
name due_on Inputs T-Minus
General Information 2023-01-25 null 54
我不认为仅仅通过标准化就可以做到这一点。所以我开始:
df = pd.json_normalize(test,
record_path =['custom_fields'],
record_prefix='_',
errors='ignore',
meta=['name', 'due_on'])
这让我想到了这样一个问题:
_name _display_value name due_on .....(extra fields that I do not need)
Inputs null General Information
T-Minus 54 General Information
我现在如何从这个数据框转到我想要的数据框?
1条答案
按热度按时间guicsvcw1#
在
pd.json_normalize
之后使用pivot
:输出: