Dropping multiple columns from Spark dataframe by Iterating through the columns from a Scala List of Column names

后端 未结 4 1841
情歌与酒
情歌与酒 2020-12-29 00:35

I have a dataframe which has columns around 400, I want to drop 100 columns as per my requirement. So i have created a Scala List of 100 column names. And then i want to ite

4条回答
  •  不知归路
    2020-12-29 01:21

    Answer:

    val colsToRemove = Seq("colA", "colB", "colC", etc) 
    
    val filteredDF = df.select(df.columns .filter(colName => !colsToRemove.contains(colName)) .map(colName => new Column(colName)): _*) 
    

提交回复
热议问题