What is the rank of each score in the DataFrame?
Using the same DataFrame, what is the rank of each 'Score' when ranked in ascending order with method='min'?
import pandas as pd
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Score': [88, 92, 85, 90]
})
df['Rank'] = df['Score'].rank(method='min')
print(df[['Name', 'Rank']].sort_values('Rank').to_dict(orient='records'))A[{'Name': 'Bob', 'Rank': 1.0}, {'Name': 'David', 'Rank': 2.0}, {'Name': 'Alice', 'Rank': 3.0}, {'Name': 'Charlie', 'Rank': 4.0}]
B[{'Name': 'Charlie', 'Rank': 1.0}, {'Name': 'Alice', 'Rank': 2.0}, {'Name': 'David', 'Rank': 3.0}, {'Name': 'Bob', 'Rank': 4.0}]
C[{'Name': 'Alice', 'Rank': 1.0}, {'Name': 'Bob', 'Rank': 2.0}, {'Name': 'Charlie', 'Rank': 3.0}, {'Name': 'David', 'Rank': 4.0}]
D[{'Name': 'David', 'Rank': 1.0}, {'Name': 'Charlie', 'Rank': 2.0}, {'Name': 'Bob', 'Rank': 3.0}, {'Name': 'Alice', 'Rank': 4.0}]
✗ Incorrect
The rank method='min' assigns the smallest rank to the lowest score. Scores 85, 88, 90, 92 get ranks 1, 2, 3, 4 respectively.