# xarray.Dataset.head

#### Dataset.head(indexers=None, \*\*indexers_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L3153-L3242)

Return a new dataset with the first n values of each array.

The values are selected along the specified dimension(s).

* **Parameters:**
  * **indexers** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict) or [`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `5`) – A dict with keys matching dimensions and integer values n
    or a single integer n applied over all dimensions.
    One of indexers or indexers_kwargs must be provided.
  * **\*\*indexers_kwargs** (`{dim: n, ...}`, *optional*) – The keyword arguments form of `indexers`.
    One of indexers or indexers_kwargs must be provided.

#### SEE ALSO
[`Dataset.tail`](xarray.Dataset.tail.html.md#xarray.Dataset.tail), [`Dataset.thin`](xarray.Dataset.thin.html.md#xarray.Dataset.thin), [`DataArray.head`](xarray.DataArray.head.html.md#xarray.DataArray.head)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('b83e7826-5b07-44c9-a131-f7da8fc1c4b9','bd92473f-3c87-4d79-a4b5-f7eb5a2326c0','c2396f14-a2a5-4aca-90d6-21f893868379','../lite/tree/../notebooks/index.html?path=608c464f_ca82_46e9_8562_abd43169ecd6.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dates = pd.date_range(start="2023-01-01", periods=5)
>>> pageviews = [1200, 1500, 900, 1800, 2000]
>>> visitors = [800, 1000, 600, 1200, 1500]
>>> dataset = xr.Dataset(
...     {
...         "pageviews": (("date"), pageviews),
...         "visitors": (("date"), visitors),
...     },
...     coords={"date": dates},
... )
>>> busiest_days = dataset.sortby("pageviews", ascending=False)
>>> busiest_days.head()
<xarray.Dataset> Size: 120B
Dimensions:    (date: 5)
Coordinates:
  * date       (date) datetime64[us] 40B 2023-01-05 2023-01-04 ... 2023-01-03
Data variables:
    pageviews  (date) int64 40B 2000 1800 1500 1200 900
    visitors   (date) int64 40B 1500 1200 1000 800 600
```

# Retrieve the 3 most busiest days in terms of pageviews

```pycon
>>> busiest_days.head(3)
<xarray.Dataset> Size: 72B
Dimensions:    (date: 3)
Coordinates:
  * date       (date) datetime64[us] 24B 2023-01-05 2023-01-04 2023-01-02
Data variables:
    pageviews  (date) int64 24B 2000 1800 1500
    visitors   (date) int64 24B 1500 1200 1000
```

# Using a dictionary to specify the number of elements for specific dimensions

```pycon
>>> busiest_days.head({"date": 3})
<xarray.Dataset> Size: 72B
Dimensions:    (date: 3)
Coordinates:
  * date       (date) datetime64[us] 24B 2023-01-05 2023-01-04 2023-01-02
Data variables:
    pageviews  (date) int64 24B 2000 1800 1500
    visitors   (date) int64 24B 1500 1200 1000
```

<div id="c2396f14-a2a5-4aca-90d6-21f893868379" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('b83e7826-5b07-44c9-a131-f7da8fc1c4b9','c2396f14-a2a5-4aca-90d6-21f893868379')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('b83e7826-5b07-44c9-a131-f7da8fc1c4b9','c2396f14-a2a5-4aca-90d6-21f893868379')">Open In Tab</button></div><div id="bd92473f-3c87-4d79-a4b5-f7eb5a2326c0" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
