[英]Find the data type of a structfield in dataset
I have a dataset, which has the following schema:我有一个数据集,它具有以下架构:
ds.schema()
0 = {StructField@21690} "StructField(col_name_1,NullType,true)"
1 = {StructField@21691} "StructField(col_name_2,StringType,true)"
2 = {StructField@21692} "StructField(col_name_3,ArrayType(StructType(StructField(person_name,StringType,true), StructField(person_surname,StringType,true)),true),true)"
I want to access the datatype of each StructField.我想访问每个 StructField 的数据类型。 Eg
if the data type of col_name_1 is NullType print null.
例如
if the data type of col_name_1 is NullType print null.
How can I build this if loop?如何构建这个 if 循环?
You can pull this out of the schema:您可以将其从架构中提取出来:
for field in df.schema.fields: print(field.name +" , "+str(field.dataType))
这对我来说很好:
ds.schema().apply(ColName).dataType().toString().equals("NullType")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.