@@ -3337,15 +3337,6 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False,
3337
3337
return self .sort_index (level = level , axis = axis , ascending = ascending ,
3338
3338
inplace = inplace , sort_remaining = sort_remaining )
3339
3339
3340
- def _nsorted (self , columns , n , method , keep ):
3341
- if not is_list_like (columns ):
3342
- columns = [columns ]
3343
- columns = list (columns )
3344
- ser = getattr (self [columns [0 ]], method )(n , keep = keep )
3345
- ascending = dict (nlargest = False , nsmallest = True )[method ]
3346
- return self .loc [ser .index ].sort_values (columns , ascending = ascending ,
3347
- kind = 'mergesort' )
3348
-
3349
3340
def nlargest (self , n , columns , keep = 'first' ):
3350
3341
"""Get the rows of a DataFrame sorted by the `n` largest
3351
3342
values of `columns`.
@@ -3378,7 +3369,7 @@ def nlargest(self, n, columns, keep='first'):
3378
3369
1 10 b 2
3379
3370
2 8 d NaN
3380
3371
"""
3381
- return self . _nsorted ( columns , n , 'nlargest' , keep )
3372
+ return algos . select_n_frame ( self , columns , n , 'nlargest' , keep )
3382
3373
3383
3374
def nsmallest (self , n , columns , keep = 'first' ):
3384
3375
"""Get the rows of a DataFrame sorted by the `n` smallest
@@ -3412,7 +3403,7 @@ def nsmallest(self, n, columns, keep='first'):
3412
3403
0 1 a 1
3413
3404
2 8 d NaN
3414
3405
"""
3415
- return self . _nsorted ( columns , n , 'nsmallest' , keep )
3406
+ return algos . select_n_frame ( self , columns , n , 'nsmallest' , keep )
3416
3407
3417
3408
def swaplevel (self , i = - 2 , j = - 1 , axis = 0 ):
3418
3409
"""
0 commit comments