Skip to content

Commit 56ff724

Browse files
committed
code review for nsmallest
1 parent 479728f commit 56ff724

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/core/frame.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7683,15 +7683,24 @@ def nsmallest(
76837683
76847684
When using ``keep='all'``, the number of element kept can go beyond ``n``
76857685
if there are duplicate values for the largest element, all the
7686-
ties are kept. However, ``nsmallest`` does not keep ``n`` distinct
7687-
smallest elements:
7686+
ties are kept.
76887687
76897688
>>> df.nsmallest(3, 'population', keep='all')
76907689
population GDP alpha-2
76917690
Tuvalu 11300 38 TV
76927691
Anguilla 11300 311 AI
76937692
Iceland 337000 17036 IS
76947693
Nauru 337000 182 NR
7694+
7695+
However, ``nsmallest`` does not keep ``n`` distinct
7696+
smallest elements:
7697+
7698+
>>> df.nsmallest(4, 'population', keep='all')
7699+
population GDP alpha-2
7700+
Tuvalu 11300 38 TV
7701+
Anguilla 11300 311 AI
7702+
Iceland 337000 17036 IS
7703+
Nauru 337000 182 NR
76957704
76967705
To order by the smallest values in column "population" and then "GDP", we can
76977706
specify multiple columns like in the next example.

0 commit comments

Comments
 (0)