Maybe a little bit off topic, but here is the solution using Scala. Make an Array
of column names from your oldDataFrame
and delete the columns that you want to drop ("colExclude")
. Then pass the Array[Column]
to select
and unpack it.
val columnsToKeep: Array[Column] = oldDataFrame.columns.diff(Array("colExclude"))
.map(x => oldDataFrame.col(x))
val newDataFrame: DataFrame = oldDataFrame.select(columnsToKeep: _*)