Return the smallest `n` elements. Parameters ---------- n : int, default 5 Return this many ascending sorted values. keep : {'first', 'last', 'all'}, default 'first' When there are duplicate values that cannot all fit in a
(
self, n: int = 5, keep: Literal["first", "last", "all"] = "first"
)
| 1657 | return result |
| 1658 | |
| 1659 | def nsmallest( |
| 1660 | self, n: int = 5, keep: Literal["first", "last", "all"] = "first" |
| 1661 | ) -> Series: |
| 1662 | """ |
| 1663 | Return the smallest `n` elements. |
| 1664 | |
| 1665 | Parameters |
| 1666 | ---------- |
| 1667 | n : int, default 5 |
| 1668 | Return this many ascending sorted values. |
| 1669 | keep : {'first', 'last', 'all'}, default 'first' |
| 1670 | When there are duplicate values that cannot all fit in a |
| 1671 | Series of `n` elements: |
| 1672 | |
| 1673 | - ``first`` : return the first `n` occurrences in order |
| 1674 | of appearance. |
| 1675 | - ``last`` : return the last `n` occurrences in reverse |
| 1676 | order of appearance. |
| 1677 | - ``all`` : keep all occurrences. This can result in a Series of |
| 1678 | size larger than `n`. |
| 1679 | |
| 1680 | Returns |
| 1681 | ------- |
| 1682 | Series |
| 1683 | The `n` smallest values in the Series, sorted in increasing order. |
| 1684 | |
| 1685 | See Also |
| 1686 | -------- |
| 1687 | Series.nlargest: Get the `n` largest elements. |
| 1688 | Series.sort_values: Sort Series by values. |
| 1689 | Series.head: Return the first `n` rows. |
| 1690 | |
| 1691 | Notes |
| 1692 | ----- |
| 1693 | Faster than ``.sort_values().head(n)`` for small `n` relative to |
| 1694 | the size of the ``Series`` object. |
| 1695 | |
| 1696 | Examples |
| 1697 | -------- |
| 1698 | >>> s = pd.Series([1, 2, 3, 4, 5, 6]) |
| 1699 | |
| 1700 | >>> s |
| 1701 | 0 1 |
| 1702 | 1 2 |
| 1703 | 2 3 |
| 1704 | 3 4 |
| 1705 | 4 5 |
| 1706 | 5 6 |
| 1707 | dtype: int64 |
| 1708 | |
| 1709 | >>> s.groupby([1, 1, 1, 2, 2, 2]).nsmallest(n=2) |
| 1710 | 1 0 1 |
| 1711 | 1 2 |
| 1712 | 2 3 4 |
| 1713 | 4 5 |
| 1714 | dtype: int64 |
| 1715 | """ |
| 1716 | f = partial(Series.nsmallest, n=n, keep=keep) |
nothing calls this directly
no test coverage detected