How do we rank employee salaries within each department, leaving gaps for tied values (e.g. 1, 2, 2, 4)?
rank().over(windowSpec) computes standard ranks with gap jumps after tied values.
Competition leaderboards, salary tiering, and performance rank audits.
from pyspark.sql.window import Window
from pyspark.sql.functions import col, rank
window_spec = Window.partitionBy("department").orderBy(col("salary").desc())
df = df.withColumn("rank", rank().over(window_spec))Practice typing production-grade PySpark code for Ranking with Gaps using rank().