Вы можете использовать orderBy
и определить свой заказ, используя when
:
from pyspark.sql.functions col, when
df.orderBy(when(col("Speed") == "Super Fast", 1)
.when(col("Speed") == "Fast", 2)
.when(col("Speed") == "Medium", 3)
.when(col("Speed") == "Slow", 4)
)