Adding a column of rowsums across a list of columns in Spark Dataframe

后端 未结 4 1639
北恋
北恋 2020-12-14 18:03

I have a Spark dataframe with several columns. I want to add a column on to the dataframe that is a sum of a certain number of the columns.

For example, my data l

4条回答
  •  遥遥无期
    2020-12-14 18:21

    Here's an elegant solution using python:

    NewDF = OldDF.withColumn('sums', sum(OldDF[col] for col in OldDF.columns[1:]))
    

    Hopefully this will influence something similar in Spark ... anyone?.

提交回复
热议问题