I am trying to add an empty column in between two columns in a dataframe select statement.
Using the withColumn
function, I'm able to append only as an end column, but I need the empty column in the middle (3rd column & 6th column) as shown below.
val product1 = product.select("_c1","_c2"," ","_c4", "_c5", "_c5", " ", "c6")
I tried using withColumn
in the middle of the select
statement as shown below which gives the error:
val product1 = product.select("_c1","_c2",product.withColumn("NewCol",lit(None).cast("string")),"_c4", "_c5", "_c5", " ", "c6")
>error: overloaded method value select with alternatives:
(col: String,cols: String*)org.apache.spark.sql.DataFrame <and>
(cols: org.apache.spark.sql.Column*)org.apache.spark.sql.DataFrame
cannot be applied to (String, String, String, String, String, String, String, String, org.apache.spark.sql.DataFrame, String)
Please let me know if any suggestions. Thanks