Q:

Pandas evaluate based on value in other rows

I have the following data frame:
data=[{
    'structural_type': 1,
    'directors': 'Ertil Altanaj',
    'ft_score': 255.54696655273438,
}, {
    'structural_type': 1,
    'directors': 'Erbil Altanaj',
    'ft_score': 14.529092788696289,
}, {
    'structural_type': 1,
    'directors': 'Richard Klemann',
    'ft_score': 202.32211303710938,
}]
df=pd.DataFrame(data)

How would I get the index in decreasing order of the fts_score. For example, the answer would look like this:
   structural_type        directors    ft_score  ft_score_index
0                1    Ertil Altanaj  255.546967               1
1                1    Erbil Altanaj   14.529093               3
2                1  Richard Klemann  202.322113               2

How can that be done?

A:

Pandas .rank() function
You can use pandas .rank() function on a column to get these indices, and pass in the parameter ascending=False to rank them in decreasing order
df["ft_score_index"] = df["ft_score"].rank(ascending=False)

