dtoolkit.accessor.series.top_n#

dtoolkit.accessor.series.top_n(s: Series, /, n: int = 5, largest: bool = True, keep: Literal['first', 'last', 'all'] = 'first') Series[source]#

Return the top n values.

A sugary syntax wraps nlargest() and nsmallest() methods.

Parameters:
nint, default 5

Number of top to return.

largestbool, default True
  • True, the top is the largest.

  • True, the top is the smallest.

keep{“first”, “last”, “all”}, default “first”

Where there are duplicate values:

  • first : prioritize the first occurrence(s).

  • last : prioritize the last occurrence(s).

  • all : do not drop any duplicates, even it means selecting more than n items.

Returns:
Series

See also

dtoolkit.accessor.series.expand

Transform each element of a list-like to a column.

dtoolkit.accessor.dataframe.top_n

Returns each row’s top n.