I would like to create a column on my spark dataframe with operations on two columns.
I want to create the column Areas which is calculated with the formula:
( (Pct_Buenos_Acum[i]-Pct_Buenos_Acum[i-1]) * (Pct_Malos_Acum[i]+Pct_Malos_Acum[i-1]) ) / 2
I have tried this:
w = Window.rowsBetween(Window.unboundedPreceding, Window.currentRow)
df= df.withColumn('Areas', (( ( col('Pct_Acum_buenos')-col('Pct_Acum_buenos' ) )*(col('Pct_Acum_malos')+col('Pct_Acum_malos')))/2).over(w))
