| [ Web Proxy ] |
| Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.pandas.DataFrame.nlargest.html | [Back] [Original] |
Section Navigation
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), but more
performant.
Note
This function cannot be used with all column types. For example, when
specifying columns with object or category dtypes, TypeError is
raised.
Examples:
>>> import bigframes.pandas as bpd
>>> df = bpd.DataFrame({"A": [1, 1, 3, 3, 5, 5],
... "B": [5, 6, 3, 4, 1, 2],
... "C": ['a', 'b', 'a', 'b', 'a', 'b']})
>>> df
A B C
0 1 5 a
1 1 6 b
2 3 3 a
3 3 4 b
4 5 1 a
5 5 2 b
[6 rows x 3 columns]
Returns rows with the largest value in A, including all ties:
>>> df.nlargest(1, 'A', keep = "all")
A B C
4 5 1 a
5 5 2 b
[2 rows x 3 columns]
Returns the first row with the largest value in A, default behavior in case of ties:
>>> df.nlargest(1, 'A')
A B C
4 5 1 a
[1 rows x 3 columns]
Returns the last row with the largest value in A in case of ties:
>>> df.nlargest(1, 'A', keep = "last")
A B C
5 5 2 b
[1 rows x 3 columns]
Returns the row with the largest combined values in both A and C:
>>> df.nlargest(1, ['A', 'C'])
A B C
5 5 2 b
[1 rows x 3 columns]
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 : do not drop any duplicates, even it means
selecting more than n items.
The first n rows ordered by the given columns in descending order.
ValueError If value of keep is not first, last, or all.
Copyright 2019, Google.
Created using Sphinx 8.1.3.
Built with the PyData Sphinx Theme 0.19.0.
| Web Proxy Viewer | New URL | Original Page |