pyspark.pandas.Series.nsmallest#
- Series.nsmallest(n=5)[source]#
Return the smallest n elements.
- Parameters
- nint, default 5
Return this many ascending sorted values.
- Returns
- Series
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 theSeries
object. In pandas-on-Spark, thanks to Spark’s lazy execution and query optimizer, the two would have same performance.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.>>> 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