Append a column to Data Frame in Apache Spark 1.3

后端 未结 4 1641
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 13:41

Is it possible and what would be the most efficient neat method to add a column to Data Frame?

More specifically, column may serve as Row IDs for the existing Data

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 14:20

    not sure if it works in spark 1.3 but in spark 1.5 I use withColumn:

    import sqlContext.implicits._
    import org.apache.spark.sql.functions._
    
    
    df.withColumn("newName",lit("newValue"))
    

    I use this when I need to use a value that is not related to existing columns of the dataframe

    This is similar to @NehaM's answer but simpler

提交回复
热议问题