diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a22142904e73d..49f57c47d3ecd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7683,8 +7683,7 @@ def nsmallest( When using ``keep='all'``, the number of element kept can go beyond ``n`` if there are duplicate values for the largest element, all the - ties are kept. However, ``nsmallest`` does not keep ``n`` distinct - smallest elements: + ties are kept. >>> df.nsmallest(3, 'population', keep='all') population GDP alpha-2 @@ -7692,6 +7691,16 @@ def nsmallest( Anguilla 11300 311 AI Iceland 337000 17036 IS Nauru 337000 182 NR + + However, ``nsmallest`` does not keep ``n`` distinct + smallest elements: + + >>> df.nsmallest(4, 'population', keep='all') + population GDP alpha-2 + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + Iceland 337000 17036 IS + Nauru 337000 182 NR To order by the smallest values in column "population" and then "GDP", we can specify multiple columns like in the next example.