java - Dividing the value of 2 columns in spark dataframe -
i have table in spark stored dataframe. want dataframe(url,url1,ratio) contains ratio,where ratio = count1/count in it. how write operation it?
it's straightforward :
import spark.implicits._ val newdf = df.withcolumn("ratio", $"count1" / $"count")
this line of code add column named ration
df
, sotore result in newdf
edit 1 : (solution in java requested)
import org.apache.spark.sql.functions._ dataset<row> newdf = df.withcolumn("ration", col("count1").divide(col("count"))
Comments
Post a Comment