How add new column in dataframe on left?

I have data frame with 5 column his name is: A,B,C,D,E . I want to dataframe with 6 column, F,A,B,C,D,E.

How I can make this?

Column order shouldn’t be important, but if it is you can:

  • add the column using withColumn()
  • reorder columns as it suits you:
val df2 = dataFrame
  .withColumn("F", lit("foo"))
  .select("F", "A", "B", "C", "D", "E")

cheers,
Dinko

1 Like