0
我pyspark数据帧具有以下模式:再添加一个StructField到架构
schema = spark_df.printSchema()
root
|-- field_1: double (nullable = true)
|-- field_2: double (nullable = true)
|-- field_3 (nullable = true)
|-- field_4: double (nullable = true)
|-- field_5: double (nullable = true)
|-- field_6: double (nullable = true)
我想多一个StructField添加到架构,因此,新的模式将是这样的:
root
|-- field_1: double (nullable = true)
|-- field_1: double (nullable = true)
|-- field_2: double (nullable = true)
|-- field_3 (nullable = true)
|-- field_4: double (nullable = true)
|-- field_5: double (nullable = true)
|-- field_6: double (nullable = true)
我知道我可以手动创建new_schema象下面这样:
new_schema = StructType([StructField("field_0", StringType(), True),
:
StructField("field_6", IntegerType(), True)])
这适用于少数领域的卜如果我有数百个字段,t就不会生成。所以我想知道是否有一个更优雅的方式来添加一个新的字段到模式的开始?谢谢!
我得到了以下错误: ----> 5 StructType(to_prepend + schema.fields) AttributeError的: 'NoneType' 对象没有属性'fields' – Edamame
我的意思是如果模式确实是一个模式。你执行'spark_df.printSchema()',它不返回有用的值。 – zero323