I have the below dataframe with me
+---+-----+---+
| ID|Month|val|
+---+-----+---+
| M1| Jan| 10|
| M1| Feb| 20|
| M1| Mar| 30|
| M2| Jan| 22|
| M2| Feb| 33|
| M3| Jan| 30|
| M3| Feb| 30|
| M4| Jan| 40|
| M4| Feb| 39|
+---+-----+---+
created by -
val df1=Seq(
("M1","Jan","10"),
("M1","Feb","20"),
("M1","Mar","30"),
("M2","Jan","22"),
("M2","Feb","33"),
("M3","Jan","30"),
("M3","Feb","30"),
("M4","Jan","40"),
("M4","Feb","39")
).toDF("ID","Month","val")
I have to find out those row whose val are lesser than or equal to the previous months.
Expected Result -
+---+-----+---+-------+
| ID|Month|val| Res|
+---+-----+---+-------+
| M1| Jan| 10| true |
| M1| Feb| 20| true |
| M1| Mar| 30| true |
| M2| Jan| 22| true |
| M2| Feb| 33| true |
| M3| Jan| 30| true |
| M3| Feb| 30| false |
| M4| Jan| 40| true |
| M4| Feb| 39| false |
+---+-----+---+-------+
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…