Series.
nsmallest
Return the smallest n elements.
Return this many ascending sorted values.
The n smallest values in the Series, sorted in increasing order.
See also
Series.nlargest
Get the n largest elements.
Series.sort_values
Sort Series by values.
Series.head
Return the first n rows.
Notes
Faster than .sort_values().head(n) for small n relative to the size of the Series object. In pandas-on-Spark, thanks to Spark’s lazy execution and query optimizer, the two would have same performance.
.sort_values().head(n)
Series
Examples
>>> data = [1, 2, 3, 4, np.nan ,6, 7, 8] >>> s = ps.Series(data) >>> s 0 1.0 1 2.0 2 3.0 3 4.0 4 NaN 5 6.0 6 7.0 7 8.0 dtype: float64
The n largest elements where n=5 by default.
n=5
>>> s.nsmallest() 0 1.0 1 2.0 2 3.0 3 4.0 5 6.0 dtype: float64
>>> s.nsmallest(3) 0 1.0 1 2.0 2 3.0 dtype: float64