bigframes.pandas.Series.nsmallest#
- Series.nsmallest(n: int = 5, keep: str = 'first') Series[source]#
Return the smallest n elements.
Examples:
>>> import bigframes.pandas as bpd >>> countries_population = {"Italy": 59000000, "France": 65000000, ... "Malta": 434000, "Maldives": 434000, ... "Brunei": 434000, "Iceland": 337000, ... "Nauru": 11300, "Tuvalu": 11300, ... "Anguilla": 11300, "Montserrat": 5200} >>> s = bpd.Series(countries_population) >>> s Italy 59000000 France 65000000 Malta 434000 Maldives 434000 Brunei 434000 Iceland 337000 Nauru 11300 Tuvalu 11300 Anguilla 11300 Montserrat 5200 dtype: Int64
The n smallest elements where n=5 by default.
>>> s.nsmallest() Montserrat 5200 Nauru 11300 Tuvalu 11300 Anguilla 11300 Iceland 337000 dtype: Int64
The n smallest elements where n=3. Default keep value is first so Nauru and Tuvalu will be kept.
>>> s.nsmallest(3) Montserrat 5200 Nauru 11300 Tuvalu 11300 dtype: Int64
The n smallest elements where n=3 with all duplicates kept. Note that the returned Series has four elements due to the three duplicates.
>>> s.nsmallest(3, keep='all') Montserrat 5200 Nauru 11300 Tuvalu 11300 Anguilla 11300 dtype: Int64
- Parameters:
n (int, default 5) – Return this many ascending sorted values.
keep ({'first', 'last', 'all'}, default 'first') –
When there are duplicate values that cannot all fit in a Series of n elements:
first: return the first n occurrences in order of appearance.last: return the last n occurrences in reverse order of appearance.all: keep all occurrences. This can result in a Series of size larger than n.
- Returns:
The n smallest values in the Series, sorted in increasing order.
- Return type: