from pyspark.sql.functions import * from pyspark.sql.window import Window ranked = df.withColumn( "rank", dense_rank().over(Window.partitionBy("A").orderBy(desc("C"))))