皮斯帕克。如何创造出像那样的谢玛?

2024-10-03 02:32:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图创建这样的模式:

root
 |-- _ehid: string (nullable = true)
 |-- duration: double (nullable = true)
 |-- list: array (nullable = true)
 |    |-- element: array (containsNull = true)
 |    |    |-- element: string (containsNull = true)
 |-- request.id: string (nullable = true)

但我只能创造一个:

root
 |-- _ehid: string (nullable = true)
 |-- duration: double (nullable = true)
 |-- list: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- element: string (nullable = true)
 |-- request.id: string (nullable = true)

对于元素,我看到的是结构类型而不是数组。当我试图通过df.show(10)查看我的df时,我只看到空值

我的剧本:

schema = StructType([
    StructField("_ehid", StringType(), True),
    StructField("duration", DoubleType(), True),
    StructField("list", ArrayType(StructType([
            StructField("element", StringType())
        ])), True),
    StructField("request.id", StringType(), True)])

Tags: idtruestringrequestrootelementarraylist
1条回答
网友
1楼 · 发布于 2024-10-03 02:32:20

直接使用StringType

schema = StructType([
    StructField("_ehid", StringType(), True),
    StructField("duration", DoubleType(), True),
    StructField("list", ArrayType(ArrayType(StringType())), True),
    StructField("request.id", StringType(), True)])

相关问题 更多 >