How to create an empty DataFrame? Why “ValueError: RDD is empty”?

后端 未结 11 1132
孤城傲影
孤城傲影 2021-02-01 03:48

I am trying to create an empty dataframe in Spark (Pyspark).

I am using similar approach to the one discussed here enter link description here, but it is not working.

11条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 04:08

    This will work with spark version 2.0.0 or more

    from pyspark.sql import SQLContext
    sc = spark.sparkContext
    schema = StructType([StructField('col1', StringType(), False),StructField('col2', IntegerType(), True)])
    sqlContext.createDataFrame(sc.emptyRDD(), schema)
    

提交回复
热议问题