我试图构造一个复杂的模式结构(StructType),以便在加载JSON文件时映射到数据帧,但是我遇到了一个错误
'type' object is not subscriptable
下面是我正在尝试的一段代码:
from pyspark.sql.types import StructField, StringType, IntegerType, StructType
baseshema = StructType[StructField('ID Number', StringType(), True),
StructField('Entity Name', StringType(), True),
StructField('Phone Number', StringType(), True),
StructField('Address',StructType[StructField('Building', StringType(), True),
StructField('Street', StringType(), True),
StructField('City', StringType(), True),
StructField('State', StringType(), True),
StructField('Postcode', StringType(), True)]),
StructField('Location',StructType[StructField('Latitude', StringType(), True),
StructField('Longitude', StringType(), True),
StructField('Location', StringType(), True)])]
必须使用括号来调用构造函数。此外,init使用一个参数,因此必须将字段包装在列表中。应该是这样的:
相关问题 更多 >
编程相关推荐