table["sort_id"] = table["playtime"].groupby(table["filename"]).rank(ascending=0)#,method="dense") table.sort_values(by=["filename","sort_id"],inplace=True)