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

posted @ 2021-01-07 13:53  船长博客  阅读(1844)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!