I am looking at the window
slide function for a Spark DataFrame
in Scala.
I have a DataFrame
with columns Col1
, Col2
, Col3
, date
, volume
and new_col
.
Col1 Col2 Col3 date volume new_col
201601 100.5
201602 120.6 100.5
201603 450.2 120.6
201604 200.7 450.2
201605 121.4 200.7`
Now I want to add a new column with name(new_col
) with one row slided down, as shown above.
I tried below option to use the window function.
val windSldBrdrxNrx_df = df.withColumn("Prev_brand_rx", lag("Prev_brand_rx",1))
Do you have any suggestion ?