我有以下DataFrame模式:
root
|-- event: struct (nullable = false)
| |-- code: string (nullable = true)
| |-- idEvent: string (nullable = true)
| |-- contract: struct (nullable = false)
| | |-- idApplication: string (nullable = true)
| |-- version: struct (nullable = false)
| | |-- idVersion: string (nullable = true)
| | |-- entity: array (nullable = false)
| | | |-- element: struct (containsNull = false)
| | | | |-- idEntity: string (nullable = true)
| | | | |-- entityType: array (nullable = false)
| | | | | |-- element: struct (containsNull = false)
| | | | | | |-- entityNumber: string (nullable = true)
| | | | | | |-- entityVersion: array (nullable = false)
| | | | | | | |-- element: struct (containsNull = false)
| | | | | | | | |-- entityCode: string (nullable = true)
| | | | | | | | |-- idCode: string (nullable = true)
从这个模式中,我们得到了一个由单个列组成的DataFrame:event
.
我希望检索位于entityVersion
数组中的idCode
属性。您知道是否有一种方法可以检索idCode
值,而不必使用explode
之类的方法来扁平化整个DataFrame吗?
非常感谢!
1条答案
按热度按时间4nkexdtk1#
首先使用
df
变量加载json,然后像下面的代码一样使用select
不需要取整个数据或
explode
列。