如何计算DataFrame列的2的幂(How to calculate the power of 2 for the column of DataFrame)
我需要使用Spark 2.2和Scala计算列p的2的幂:
但如果我这样做,我得到错误,因为($"ki" / $"ni")是列,而不是Double。
df.withColumn("p",(lit(1) - scala.math.pow(($"ki" / $"ni").as[Double],2))I need to calculate the power of 2 for the column p using Spark 2.2 and Scala:
But if I do it this way, I get the error, because ($"ki" / $"ni") is the column, not Double.
df.withColumn("p",(lit(1) - scala.math.pow(($"ki" / $"ni").as[Double],2))最满意答案
你可以使用内置的pow功能
import org.apache.spark.sql.functions._ df.withColumn("power_of_two", pow($"p", lit(2)))you can use inbuilt pow function as
import org.apache.spark.sql.functions._ df.withColumn("power_of_two", pow($"p", lit(2)))更多推荐
发布评论