I am trying to find the equivalent Pyspark code for the below R Code.
mutate(Target.1 = lag(Target, 3),Sales.1 = lag(Sales, 3))
I think using Window functions ought to work, though you would need something to order by:
import pyspark.sql.functions as func from pyspark.sql.window import Window window = Window.partitionBy("Model").orderBy( ??? ) car = car.withColumn("Target.1", func.lag("Target", 3).over(window))\ .withColumn("Sales.1", func.lag("Sales", 3))