Reputation: 2747
I have a pandas dataFrame that consist of the following:
Athlete A Athlete B Athlete C
speed=10 speed=12 speed=6
endurance=60 endurance=59 endurance=64
I would like to rank the strength of those three Athletes based on their speed and endurance. I would like to give a slightly greater weight (0.6) to the endurance. Is there any python library to do rankings based on multiple conditions?
Upvotes: 1
Views: 7410
Reputation: 2120
You should add a new column to your dataframe with the calculated order and then sort it by that column. Example:
import pandas as pd
df = pd.DataFrame({'Athlete': ['A','B','C'],
'Speed': [10,12,6],
'Endurance': [60,59,64]})
df['sorting_column'] = df.Speed*0.4 + df.Endurance*0.6 #I think you want 40% speed and 60% endurance right?
df.sort(columns='sorting_column')
Result:
Athlete Endurance Speed sorting_column
2 C 64 6 29.2
0 A 60 10 30.0
1 B 59 12 30.8
Upvotes: 6