Get n-largest values from a particular column in Pandas DataFrame

Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).

Let’s see how can we can get n-largest values from a particular column in Pandas DataFrame.

Observe this dataset first. We’ll use ‘Age’, ‘Weight’ and ‘Salary’ columns of this data in order to get n-largest values from a particular column in Pandas DataFrame.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas module 
import pandas as pd 
    
# making data frame 
  
df.head(10)

chevron_right


Code #1: Getting 5 largest Age



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas module 
import pandas as pd 
    
# making data frame 
df = pd.read_csv("nba.csv"
  
# five largest values in column age
df.nlargest(5, ['Age'])

chevron_right


Output:

 

Code #2: Getting 10 maximum weights

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas module 
import pandas as pd 
    
# making data frame 
df = pd.read_csv("nba.csv"
  
# Ten largest values in column Weight
df.nlargest(10, ['Weight'])

chevron_right


Output:

 

Code #3: Getting 10 maximum salary

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas module 
import pandas as pd 
    
# making data frame 
df = pd.read_csv("nba.csv"
  
# five largest values in column Salary
df.nlargest(5, ['Salary'])

chevron_right


Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.