Return the largest n elements.

param n
int, default 5

Return this many descending sorted values.

param keep
{‘first’, ‘last’, ‘all’}, default ‘first’

When there are duplicate values that cannot all fit in a Series of n elements:

  • firstreturn the first n occurrences in order

    of appearance.

  • lastreturn the last n occurrences in reverse

    order of appearance.

  • allkeep all occurrences. This can result in a Series of

    size larger than n.


Series The n largest values in the Series, sorted in decreasing order.


  • Parameter keep is supported only with default value 'first'.

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff

    between staying in JIT-region with that function or going back to interpreter mode.


Returns the largest n elements.
import numpy as np
import pandas as pd
from numba import njit

def series_nlargest():
    series = pd.Series(np.arange(10))

    return series.nlargest(4)  # Expect series of 9, 8, 7, 6

$ python ./series/
9    9
8    8
7    7
6    6
dtype: int64

See also


Get the n smallest elements.


Sort Series by values.


Return the first n rows.