We can do this with when otherwise and lag
from pyspark.sql import functions as F
from pyspark.sql import Window
schema="Customer string,day int,Amount int"
data=[('A',4,96),('A',22,63),('A',32,19),('A',50,27),('A',57,99),('A',72,93),('B',69,97),('B',82,22),('B',87,64),('C',22,60),('C',30,22),('C',48,74),('C',49,68),('C',55,11),('C',85,79)]
dql=spark.createDataFrame(data,schema)
dql.withColumn("count",when((col('Amount')>F.lag("Amount",2).over(Window.partitionBy("Customer").orderBy("day"))) & (col('Amount')>F.lag("Amount",1).over(Window.partitionBy("Customer").orderBy("day"))) ,2).when((col('Amount')>F.lag("Amount",2).over(Window.partitionBy("Customer").orderBy("day"))) | (col('Amount')>F.lag("Amount",1).over(Window.partitionBy("Customer").orderBy("day"))) ,1).otherwise("0")).show()
#output
+--------+---+------+-----+
|Customer|day|Amount|count|
+--------+---+------+-----+
| A| 4| 96| 0|
| A| 22| 63| 0|
| A| 32| 19| 0|
| A| 50| 27| 1|
| A| 57| 99| 2|
| A| 72| 93| 1|
| B| 69| 97| 0|
| B| 82| 22| 0|
| B| 87| 64| 1|
| C| 22| 60| 0|
| C| 30| 22| 0|
| C| 48| 74| 2|
| C| 49| 68| 1|
| C| 55| 11| 0|
| C| 85| 79| 2|
+--------+---+------+-----+