# dask.dataframe.Index.nsmallest

#### Index.nsmallest(n=5, split_every=None)

Return the smallest n elements.

This docstring was copied from pandas.Series.nsmallest.

Some inconsistencies with the Dask version may exist.

This method is optimized for performance compared to sorting the
entire Series when only a few of the bottom values are needed.

* **Parameters:**
  **n**
  : Return this many ascending sorted values.

  **keep**
  : When there are duplicate values that cannot all fit in a
    Series of n elements:
    - `first` : return the first n occurrences in order
      of appearance.
    - `last` : return the last n occurrences in reverse
      order of appearance.
    - `all` : keep all occurrences. This can result in a Series of
      size larger than n.
* **Returns:**
  Series
  : The n smallest values in the Series, sorted in increasing order.

#### SEE ALSO
[`Series.nlargest`](dask.dataframe.Series.nlargest.html.md#dask.dataframe.Series.nlargest)
: Get the n largest elements.

`Series.sort_values`
: Sort Series by values.

[`Series.head`](dask.dataframe.Series.head.html.md#dask.dataframe.Series.head)
: Return the first n rows.

### Notes

Faster than `.sort_values().head(n)` for small n relative to
the size of the `Series` object.

### Examples

```pycon
>>> countries_population = {
...     "Italy": 59000000,
...     "France": 65000000,
...     "Brunei": 434000,
...     "Malta": 434000,
...     "Maldives": 434000,
...     "Iceland": 337000,
...     "Nauru": 11300,
...     "Tuvalu": 11300,
...     "Anguilla": 11300,
...     "Montserrat": 5200,
... }
>>> s = pd.Series(countries_population)
>>> s
Italy       59000000
France      65000000
Brunei        434000
Malta         434000
Maldives      434000
Iceland       337000
Nauru          11300
Tuvalu         11300
Anguilla       11300
Montserrat      5200
dtype: int64
```

The n smallest elements where `n=5` by default.

```pycon
>>> s.nsmallest()
Montserrat    5200
Nauru        11300
Tuvalu       11300
Anguilla     11300
Iceland     337000
dtype: int64
```

The n smallest elements where `n=3`. Default keep value is
‘first’ so Nauru and Tuvalu will be kept.

```pycon
>>> s.nsmallest(3)
Montserrat   5200
Nauru       11300
Tuvalu      11300
dtype: int64
```

The n smallest elements where `n=3` and keeping the last
duplicates. Anguilla and Tuvalu will be kept since they are the last
with value 11300 based on the index order.

```pycon
>>> s.nsmallest(3, keep="last")
Montserrat   5200
Anguilla    11300
Tuvalu      11300
dtype: int64
```

The n smallest elements where `n=3` with all duplicates kept. Note
that the returned Series has four elements due to the three duplicates.

```pycon
>>> s.nsmallest(3, keep="all")
Montserrat   5200
Nauru       11300
Tuvalu      11300
Anguilla    11300
dtype: int64
```

<!-- !! processed by numpydoc !! -->
