【发布时间】:2023-02-08 02:38:08
【问题描述】:
是否可以选择一个特定的 JSON 数组(对应于下面的名称“contents”)并将该数组更改为 pandas 数据框?我的json如下
html_sample3 = """{
"orderID": 12345,
"shopperName": "John Smith",
"shopperEmail": "johnsmith@example.com",
"contents": [
{
"productID": 34,
"productName": "SuperWidget",
"quantity": 1
},
{
"productID": 56,
"productName": "WonderWidget",
"quantity": 3
}
],
"orderCompleted": true
}"""
我写的代码非常稀疏,难倒了这一点。
from bs4 import BeautifulSoup
import pandas as pd
soup1 = BeautifulSoup(html_sample3)
我想要的数据框如下所示。
【问题讨论】:
标签: python json pandas dataframe beautifulsoup