# xarray.Dataset.head

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

Returns a new dataset with the first n values of each array
for 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.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('ac940c6d-d408-433c-97f5-ec0433605ee0','75a8b728-61eb-4fb8-9dff-5fe87c730dea','c2cee650-fcb0-4d30-9299-b611b277148e','../lite/tree/../notebooks/index.html?path=a880e52d_db21_4595_ad28_85c0a58636f8.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="c2cee650-fcb0-4d30-9299-b611b277148e" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('ac940c6d-d408-433c-97f5-ec0433605ee0','c2cee650-fcb0-4d30-9299-b611b277148e')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('ac940c6d-d408-433c-97f5-ec0433605ee0','c2cee650-fcb0-4d30-9299-b611b277148e')">Open In Tab</button></div><div id="75a8b728-61eb-4fb8-9dff-5fe87c730dea" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### 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)
