structtype有一个方法调用add。我看到了使用的例子
schema = Structype()
schema.add('testing',string)
schema.add('testing2',string)
如何使用add((在架构中添加Structtype和数组类型?
您需要按以下方式使用它-
from pyspark.sql.types import *
schema = StructType()
schema.add('testing',StringType())
schema.add('testing2',StringType())
使用此schema
-创建数据帧的示例
df = spark.createDataFrame(data=[(1,2), (3,4)],schema=schema)
df.show()
+-------+--------+
|testing|testing2|
+-------+--------+
| 1| 2|
| 3| 4|
+-------+--------+