Skip to content

Commit

Permalink
code review for nsmallest
Browse files Browse the repository at this point in the history
  • Loading branch information
MainHanzo committed Dec 11, 2023
1 parent 479728f commit 56ff724
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7683,15 +7683,24 @@ 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
Tuvalu 11300 38 TV
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.
Expand Down

0 comments on commit 56ff724

Please sign in to comment.