pyspark.pandas.groupby.SeriesGroupBy.nsmallest

SeriesGroupBy.nsmallest(n: int = 5) → pyspark.pandas.series.Series[source]

Return the smallest n elements.

Parameters
nint

Number of items to retrieve.

Examples

>>> df = ps.DataFrame({'a': [1, 1, 1, 2, 2, 2, 3, 3, 3],
...                    'b': [1, 2, 2, 2, 3, 3, 3, 4, 4]}, columns=['a', 'b'])
>>> df.groupby(['a'])['b'].nsmallest(1).sort_index()  
a
1  0    1
2  3    2
3  6    3
Name: b, dtype: int64