Add new rows to pyspark Dataframe

前端 未结 2 1710
悲&欢浪女
悲&欢浪女 2020-12-19 08:56

Am very new pyspark but familiar with pandas. I have a pyspark Dataframe

# instantiate Spark
spark = SparkSession.builder.getOrCreate()

# make some test da         


        
2条回答
  •  余生分开走
    2020-12-19 09:54

    From something I did, using union, showing a block partial coding - you need to adapt of course to your own situation:

    val dummySchema = StructType(
    StructField("phrase", StringType, true) :: Nil)
    var dfPostsNGrams2 = spark.createDataFrame(sc.emptyRDD[Row], dummySchema)
    for (i <- i_grams_Cols) {
        val nameCol = col({i})
        dfPostsNGrams2 = dfPostsNGrams2.union(dfPostsNGrams.select(explode({nameCol}).as("phrase")).toDF )
     }
    

    union of DF with itself is the way to go.

提交回复
热议问题