pandas.core.groupby.SeriesGroupBy.nsmallest
-
SeriesGroupBy.nsmallest(*args, **kwargs) -
Return the smallest
nelements.Parameters: n : int
Return this many ascending sorted values
keep : {‘first’, ‘last’, False}, default ‘first’
Where there are duplicate values: -
first: take the first occurrence. -last: take the last occurrence.take_last : deprecated
Returns: bottom_n : Series
The n smallest values in the Series, in sorted order
See also
Series.nlargestNotes
Faster than
.sort_values().head(n)for smallnrelative to the size of theSeriesobject.Examples
>>> import pandas as pd >>> import numpy as np >>> s = pd.Series(np.random.randn(1e6)) >>> s.nsmallest(10) # only sorts up to the N requested
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.core.groupby.SeriesGroupBy.nsmallest.html