I solved your problem using lag window function. Just go through the code below:
>>> from pyspark.sql.functions import lag, col
>>> from pyspark.sql.window import Window
Then, create your df:
Finally, use LAG():
w = Window().partitionBy().orderBy(col("id"))
df.select("*", lag("num").over(w).alias("new_col")).na.drop().show()