3

I have a dataframe that i want to make a unionAll with a nother dataframe. The problem is that the second dataframe has thre more columns than the first one. Is there a way for me to add three columns with only empty cells in my first dataframe?

dagrun
  • 621
  • 3
  • 11
  • 29
  • 1
    Possible duplicate of [Add an empty column to spark DataFrame](http://stackoverflow.com/questions/33038686/add-an-empty-column-to-spark-dataframe) – zero323 Feb 09 '16 at 15:40

3 Answers3

2

Maybe this will help

To add string type column:

from pyspark.sql.types import StringType

df.withColumn("COL_NAME", lit(None).cast(StringType()))

To Add integer type

from pyspark.sql.types import IntegerType

df.withColumn("COL_NAME", lit(0).cast(IntegerType()))
1

use withColumn object of spark-dataframe
DF.withColumn("NewCol","Value")

Hossein Vatani
  • 1,381
  • 14
  • 26
1

df.withColumn('NewColumn', lit(None).cast(StringType()))

dagrun
  • 621
  • 3
  • 11
  • 29