How to drop multiple column names given in a list from Spark DataFrame?
You can use the *
operator to pass the contents of your list as arguments to drop()
:
df.drop(*drop_lst)
You can give column name as comma separated list e.g.
df.drop("col1","col11","col21")
This is how drop specified number of consecutive columns in scala:
val ll = dfwide.schema.names.slice(1,5)
dfwide.drop(ll:_*).show
slice take two parameters star index and end index.