Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Window function: returns the relative rank (i.e. percentile) of rows within a window partition.
Syntax
from pyspark.sql import functions as sf
sf.percent_rank()
Parameters
This function does not take any parameters.
Returns
pyspark.sql.Column: the column for calculating relative rank.
Examples
from pyspark.sql import functions as sf
from pyspark.sql import Window
df = spark.createDataFrame([1, 1, 2, 3, 3, 4], "int")
w = Window.orderBy("value")
df.withColumn("pr", sf.percent_rank().over(w)).show()
+-----+---+
|value| pr|
+-----+---+
| 1|0.0|
| 1|0.0|
| 2|0.4|
| 3|0.6|
| 3|0.6|
| 4|1.0|
+-----+---+