I am getting the maximum value over a specific window in pyspark. But what is returned from the method is not the expected.
Here comes my codes:
test = spark.createDataFrame(DataFrame({'grp': ['a', 'a', 'b', 'b'], 'val': [2, 3, 3, 4]}))
win = Window.partitionBy('grp').orderBy('val')
test = test.withColumn('row_number', F.row_number().over(win))
test = test.withColumn('max_row_number', F.max('row_number').over(win))
display(test)
And the output is:
I expected it would return 2 for both group "a" and group "b" but it didn't.
Anyone has ideas on this problem? Thanks a lot!
