【发布时间】:2020-05-02 16:13:50
【问题描述】:
我正在尝试读取这个 json 文件。
{
"data": [{
"id": "c1",
"type": "corporate",
"tenor": "10.3 years",
"yield": "5.30%",
"amount_outstanding": 1200000
},
{
"id": "g1",
"type": "government",
"tenor": "9.4 years",
"yield": "3.70%",
"amount_outstanding": 2500000
},
]}
代码 df = spark.read.option("multiline", True).json("sample_input.json") df.select(col("data")).show()
但是,这会将所有内容读入单个列。有没有办法可以使用id、type、tenor 和其他列来应用架构?
【问题讨论】:
-
使用现有代码加载数据后,只需运行
df = df.selectExpr('inline(data)') -
@jxc 谢谢。它解决了问题