spark使用withcolumn lit新增一常数列赋值为-1
scala> val a = Seq(("a", 2),("b",3)).toDF("name","score") a: org.apache.spark.sql.DataFrame = [name: string, score: int] scala> a.show() +----+-----+ |name|score| +----+-----+ | a| 2| | b| 3| +----+-----+ scala> a.withColumn("bit", lit(-999)).show +----+-----+----+ |name|score| bit| +----+-----+----+ | a| 2|-1| | b| 3|-1| +----+-----+----+
https://stackoverflow.com/questions/32788322/how-to-add-a-constant-column-in-a-spark-dataframe