schema
df.schema df的结构描述
>> StructType(List(StructField(dt,StringType,true),StructField(age,LongType,true)))
StructField
A field in StructType.
StructField(name,dataType,nullable,metadata=None)
StructType
Struct type, consisting of a list of StructField.
This is the data type representing a Row.
struct1=StructType([StructField('f1',StringType(),True)])
add添加StructField
fieldNames 所有名字列表
struct1=T.StructType([T.StructField('f1',T.StringType(),True)]).add("f2",StringType(),True).add("newf",'float',True)
struct1['newf']
>>StructField(newf,FloatType,true)
struct1[1]
>>StructField(f2,StringType,true)
struct1.fieldNames()
>>['f1', 'f2', 'newf']