Get n-largest values from a particular column in Pandas DataFrame
df.nlargest(5, 'Gross')

Return the first n rows with the smallest values for column in DataFrame
df.nsmallest(5, ['Age'])
To order by the smallest values in column “Age” and then “Salary”, we can specify multiple columns like in the next example.
df.nsmallest(5, ['Age', 'Salary'])
There is also an optional keep
parameter for the nlargest
and nsmallest
functions. keep has three possible values: {'first', 'last', 'all'}
. The default is 'first'
Where there are duplicate values:
first
: take the first occurrence.last
: take the last occurrence.all
: do not drop any duplicates, even it means selecting more than n items.
df.nlargest(5, 'Gross', keep='last')
