嵌套结构的填充元素

问题描述 投票:0回答:1
schema = StructType(
[
    StructField('Info1',
        StructType([
            StructField('A1',
                   StructType([        
                        StructField('A11', IntegerType(),True),
                        StructField('A12', IntegerType(),True)
            ])
 ),
            StructField('A2', IntegerType(),True)
        ])
 )
df = sqlCtx.createDataFrame([],schema)
#Creation of df1
df1 = spark.createDataFrame(
[Row(
 x1=Row(field1=10, field2=1.5, x12=Row(field5='tt')), 
 x2=Row(field3="one",field4=False)
)])

现在我想要的是Info1的A11将获得x1.field2的值。

df = sqlCtx.createDataFrame(df1.rdd.map(lambda x: Row(Info1.A1=Row(A11=int(x.x1.field2), A2=None))), schema)

但我收到此错误SyntaxError:关键字不能是表达式

请提出任何解决此问题的想法。??

python pyspark syntax-error pyspark-sql aws-glue
1个回答
0
投票

[在我看来,第一个嫌疑犯是将Row嵌套在​​Row中。而且我想可以使用Python数据类型(列表和命名元组)简单地创建行。

© www.soinside.com 2019 - 2024. All rights reserved.