AA
df.withColumn("id",row_number().over(Window.orderBy("a column")))
можно так
Size: a a a
AA
AS
AA
AA
lookup = (uniq_flag.select("rank")
.distinct()
.orderBy("rank")
.rdd
.zipWithIndex()
.map(lambda x: x[0] + (x[1], ))
.toDF(["rank", "cat"]))
SK
DA
DA
SK
DA
K
AD
PK
AB
PK
PK
PK
PK
AA
meta_old.loc['date', name]
> meta_new.loc['date', name2]
PK
PK