How to find Prev and Next price from price column via pyspark
Solution:
df = spark.read.format("csv").option("header","True").load("file:////home/cloudera/npt.txt")
df.show()
dfp = df.withColumn("PrevPrice",lag("Price").over(Window.partitionBy().orderBy("Number"))).withColumn("NextPrice",lead("Price").over(Window.partitionBy().orderBy("Number"))).drop("Price","Type","Date","Time")
dfp.show()
Comments
Post a Comment