@@ -5222,7 +5222,7 @@ def nsmallest(self, n, columns, keep="first") -> "DataFrame":
5222
5222
Examples
5223
5223
--------
5224
5224
>>> df = pd.DataFrame({'population': [59000000, 65000000, 434000,
5225
- ... 434000, 434000, 337000, 11300 ,
5225
+ ... 434000, 434000, 337000, 337000 ,
5226
5226
... 11300, 11300],
5227
5227
... 'GDP': [1937894, 2583560 , 12011, 4520, 12128,
5228
5228
... 17036, 182, 38, 311],
@@ -5239,43 +5239,44 @@ def nsmallest(self, n, columns, keep="first") -> "DataFrame":
5239
5239
Maldives 434000 4520 MV
5240
5240
Brunei 434000 12128 BN
5241
5241
Iceland 337000 17036 IS
5242
- Nauru 11300 182 NR
5242
+ Nauru 337000 182 NR
5243
5243
Tuvalu 11300 38 TV
5244
5244
Anguilla 11300 311 AI
5245
5245
5246
5246
In the following example, we will use ``nsmallest`` to select the
5247
- three rows having the smallest values in column "a ".
5247
+ three rows having the smallest values in column "population ".
5248
5248
5249
5249
>>> df.nsmallest(3, 'population')
5250
- population GDP alpha-2
5251
- Nauru 11300 182 NR
5252
- Tuvalu 11300 38 TV
5253
- Anguilla 11300 311 AI
5250
+ population GDP alpha-2
5251
+ Tuvalu 11300 38 TV
5252
+ Anguilla 11300 311 AI
5253
+ Iceland 337000 17036 IS
5254
5254
5255
5255
When using ``keep='last'``, ties are resolved in reverse order:
5256
5256
5257
5257
>>> df.nsmallest(3, 'population', keep='last')
5258
5258
population GDP alpha-2
5259
5259
Anguilla 11300 311 AI
5260
5260
Tuvalu 11300 38 TV
5261
- Nauru 11300 182 NR
5261
+ Nauru 337000 182 NR
5262
5262
5263
5263
When using ``keep='all'``, all duplicate items are maintained:
5264
5264
5265
5265
>>> df.nsmallest(3, 'population', keep='all')
5266
- population GDP alpha-2
5267
- Nauru 11300 182 NR
5268
- Tuvalu 11300 38 TV
5269
- Anguilla 11300 311 AI
5266
+ population GDP alpha-2
5267
+ Tuvalu 11300 38 TV
5268
+ Anguilla 11300 311 AI
5269
+ Iceland 337000 17036 IS
5270
+ Nauru 337000 182 NR
5270
5271
5271
- To order by the largest values in column "a " and then "c ", we can
5272
+ To order by the smallest values in column "population " and then "GDP ", we can
5272
5273
specify multiple columns like in the next example.
5273
5274
5274
5275
>>> df.nsmallest(3, ['population', 'GDP'])
5275
5276
population GDP alpha-2
5276
5277
Tuvalu 11300 38 TV
5277
- Nauru 11300 182 NR
5278
5278
Anguilla 11300 311 AI
5279
+ Nauru 337000 182 NR
5279
5280
"""
5280
5281
return algorithms .SelectNFrame (
5281
5282
self , n = n , keep = keep , columns = columns
0 commit comments