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))
you can use inbuilt pow function as
import org.apache.spark.sql.functions._
df.withColumn("power_of_two", pow($"p", lit(2)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With