How to “negative select” columns in spark's dataframe

前端 未结 9 2015
野的像风
野的像风 2020-12-15 05:35

I can\'t figure it out, but guess it\'s simple. I have a spark dataframe df. This df has columns \"A\",\"B\" and \"C\". Now let\'s say I have an Array containing the name of

9条回答
  •  春和景丽
    2020-12-15 05:49

    I had the same problem and solved it this way (oaffdf is a dataframe):

    val dropColNames = Seq("col7","col121")
    val featColNames = oaffdf.columns.diff(dropColNames)
    val featCols = featColNames.map(cn => org.apache.spark.sql.functions.col(cn))
    val featsdf = oaffdf.select(featCols: _*)
    

    https://forums.databricks.com/questions/2808/select-dataframe-columns-from-a-sequence-of-string.html

提交回复
热议问题