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

前端 未结 9 2036
野的像风
野的像风 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:46

    Since Spark 1.4 you can use drop method:

    Scala:

    case class Point(x: Int, y: Int)
    val df = sqlContext.createDataFrame(Point(0, 0) :: Point(1, 2) :: Nil)
    df.drop("y")
    

    Python:

    df = sc.parallelize([(0, 0), (1, 2)]).toDF(["x", "y"])
    df.drop("y")
    ## DataFrame[x: bigint]
    

提交回复
热议问题