I've got a dataframe:
df = pd.DataFrame({
"DScore": [2, 2, 3, 4, 5],
"EScore": [6, 7, 9, 9, 10],
"Total Score": [17, 15, 15, 23, 25]
})
I want to write the code that will create a ranking column containing the classification of rows in the table based on the 'Total Score' column. If these values are equal - you should pay attention to the values of EScore points, if they are equal, then it will be based on the values from the DScore column, and if these are also equal - we will assign them the same value. Expected result:
df = pd.DataFrame({
"DScore": [2, 2, 4, 4, 5],
"EScore": [6, 7, 9, 9, 10],
"Total Score": [17, 15, 23, 23, 25],
"Rank": [3,4,2,2,1]
})
For example, you can multiply the
EScoreby 0.01 and theDScoreby 0.001 to weight them more lightly. Then, you can add these values toTotal Scoreand calculate the rank.rank with
method=dense&ascending=Falsedf
The example you provided is sufficient with
0.01and0.0001, but these numbers should be adjusted to fit the dataset.