I have pasted my code below.
I am expecting that when col2 = 7, it should return 1, but it is returning 1 at times and 2 - at other times. I am not doing any operations on col2 once it is set. Has anyone ever experienced this odd behavior? Or is the problem due to the fact that the limits for each condition are overlapping?
df = df.withColumn('col1', F.when(F.col('col2').between(1,7), 1)
.when(F.col('col2').between(7,14), 2)
.when(F.col('col2').between(14,21), 3)
.when(F.col('col2').between(21,28), 4)
.otherwise(5))