How to find the row number of nth largest value?

I am looking for a solution to find the row number of the nth largest value in a Pandas DataFrame. I need help from the community to find alternative ways to solve this problem efficiently. Suppose I have a DataFrame with two columns and I want to find the row number of the nth largest value in a specific column. One approach could be to sort the DataFrame by that column and then use the iloc function to retrieve the nth largest value and its corresponding row number. However, this can be computationally expensive for large datasets. I would like to explore alternative solutions that are more efficient and scalable. I welcome any suggestions or code snippets that can help me accomplish this task in a more efficient manner.

1 Like

Hello @nimrah , I have a solution to your query. You can use the nlargest() and index() methods of Pandas. The nlargest() method returns the n-largest values from a column in descending order and the index() method is to get the index labels of those values. Let me show you below how can we utilize them: