How to do some calculation between Columns in spark Dataframe?

后端 未结 1 1755
走了就别回头了
走了就别回头了 2021-01-25 18:52

For example, I want to plus the la and lon column and output result in another column.

+------+------------------+------------------+
|userid|               la |         


        
相关标签:
1条回答
  • 2021-01-25 19:07

    If you just need to sum two columns together, it's pretty straightforward :

    df.withColumn("x", $"la" + $"lon")
    

    x is the name of the new column.

    To elevate the column into the power of 2 :

    df.withColumn("x", pow($"la" + $"lon", 2))
    
    0 讨论(0)
提交回复
热议问题