Summing a list of columns into one column - Apache Spark SQL

PHOTO EMBED

Wed Aug 04 2021 09:11:31 GMT+0000 (UTC)

Saved by @Zyglak #scala #spark

val columnsToSum = List(col("var1"), col("var2"), col("var3"), col("var4"), col("var5"))

val output = input.withColumn("sums", columnsToSum.reduce(_ + _))
content_copyCOPY

https://stackoverflow.com/questions/37624699/adding-a-column-of-rowsums-across-a-list-of-columns-in-spark-dataframe