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 的類型
