modin.pandas.DataFrame.nlargest¶
- DataFrame.nlargest(n, columns, keep='first') DataFrame[source]¶
Return the first n rows ordered by columns in descending order.
Return the first n rows with the largest values in columns, in descending order. The columns that are not specified are returned as well, but not used for ordering.
This method is equivalent to
df.sort_values(columns, ascending=False).head(n)- Parameters:
n (int) – Number of rows to return.
columns (label or list of labels) – Column label(s) to order by.
keep ({'first', 'last', 'all'}, default 'first') –
Where there are duplicate values:
first: prioritize the first occurrence(s)last: prioritize the last occurrence(s)all: keep all the ties of the smallest item even if it means selecting more thannitems.
- Returns:
The first n rows ordered by the given columns in descending order.
- Return type:
See also
DataFrame.nsmallestReturn the first n rows ordered by columns in ascending order.
DataFrame.sort_valuesSort DataFrame by the values.
DataFrame.headReturn the first n rows without re-ordering.
Examples
In the following example, we will use
nlargestto select the three rows having the largest values in column “population”.When using
keep='last', ties are resolved in reverse order:When using
keep='all', the number of element kept can go beyondnif there are duplicate values for the smallest element, all the ties are kept:However,
nlargestdoes not keepndistinct largest elements:To order by the largest values in column “population” and then “GDP”, we can specify multiple columns like in the next example.