@@ -7505,8 +7505,8 @@ def nlargest(
7505
7505
7506
7506
- ``first`` : prioritize the first occurrence(s)
7507
7507
- ``last`` : prioritize the last occurrence(s)
7508
- - ``all`` : do not drop any duplicates, even it means
7509
- selecting more than `n ` items.
7508
+ - ``all`` : keep all the ties of the smallest item even if it means
7509
+ selecting more than ``n` ` items.
7510
7510
7511
7511
Returns
7512
7512
-------
@@ -7568,7 +7568,9 @@ def nlargest(
7568
7568
Italy 59000000 1937894 IT
7569
7569
Brunei 434000 12128 BN
7570
7570
7571
- When using ``keep='all'``, all duplicate items are maintained:
7571
+ When using ``keep='all'``, the number of element kept can go beyond ``n``
7572
+ if there are duplicate values for the smallest element, all the
7573
+ ties are kept:
7572
7574
7573
7575
>>> df.nlargest(3, 'population', keep='all')
7574
7576
population GDP alpha-2
@@ -7578,6 +7580,16 @@ def nlargest(
7578
7580
Maldives 434000 4520 MV
7579
7581
Brunei 434000 12128 BN
7580
7582
7583
+ However, ``nlargest`` does not keep ``n`` distinct largest elements:
7584
+
7585
+ >>> df.nlargest(5, 'population', keep='all')
7586
+ population GDP alpha-2
7587
+ France 65000000 2583560 FR
7588
+ Italy 59000000 1937894 IT
7589
+ Malta 434000 12011 MT
7590
+ Maldives 434000 4520 MV
7591
+ Brunei 434000 12128 BN
7592
+
7581
7593
To order by the largest values in column "population" and then "GDP",
7582
7594
we can specify multiple columns like in the next example.
7583
7595
@@ -7614,8 +7626,8 @@ def nsmallest(
7614
7626
7615
7627
- ``first`` : take the first occurrence.
7616
7628
- ``last`` : take the last occurrence.
7617
- - ``all`` : do not drop any duplicates, even it means
7618
- selecting more than `n ` items.
7629
+ - ``all`` : keep all the ties of the largest item even if it means
7630
+ selecting more than ``n` ` items.
7619
7631
7620
7632
Returns
7621
7633
-------
@@ -7669,7 +7681,9 @@ def nsmallest(
7669
7681
Tuvalu 11300 38 TV
7670
7682
Nauru 337000 182 NR
7671
7683
7672
- When using ``keep='all'``, all duplicate items are maintained:
7684
+ When using ``keep='all'``, the number of element kept can go beyond ``n``
7685
+ if there are duplicate values for the largest element, all the
7686
+ ties are kept.
7673
7687
7674
7688
>>> df.nsmallest(3, 'population', keep='all')
7675
7689
population GDP alpha-2
@@ -7678,6 +7692,16 @@ def nsmallest(
7678
7692
Iceland 337000 17036 IS
7679
7693
Nauru 337000 182 NR
7680
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
7704
+
7681
7705
To order by the smallest values in column "population" and then "GDP", we can
7682
7706
specify multiple columns like in the next example.
7683
7707
0 commit comments