from pyspark.sql.types import * from pyspark.sql import SparkSession spark = SparkSession.builder.appName('TEST').getOrCreate() sc=spark.sparkContext schema = StructType([ StructField("a", IntegerType(), True), StructField("b", IntegerType(), True), StructField("c", IntegerType(), True)]) # 通过定义好的dataframe的schema来创建空dataframe df1 = spark.createDataFrame(spark.sparkContext.emptyRDD(), schema) df1.show()
想要创建一个空的spark dataframe,需要先指定schema 的类型