小编rga*_*101的帖子

How to compose column name using another column's value for withColumn in Scala Spark

I'm trying to add a new column to a DataFrame. The value of this column is the value of another column whose name depends on other columns from the same DataFrame.

For instance, given this:

+---+---+----+----+
|  A|  B| A_1| B_2|
+---+---+----+----+
|  A|  1| 0.1| 0.3|
|  B|  2| 0.2| 0.4|
+---+---+----+----+
Run Code Online (Sandbox Code Playgroud)

I'd like to obtain this:

+---+---+----+----+----+
|  A|  B| A_1| B_2|   C|
+---+---+----+----+----+
|  A|  1| 0.1| 0.3| 0.1|
|  B|  2| 0.2| 0.4| 0.4| …
Run Code Online (Sandbox Code Playgroud)

scala apache-spark apache-spark-sql

5
推荐指数
1
解决办法
6202
查看次数

标签 统计

apache-spark ×1

apache-spark-sql ×1

scala ×1