# xarray.Dataset.isel

#### Dataset.isel(indexers=None, drop=False, missing_dims='raise', \*\*indexers_kwargs)[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataset.py#L2804-L2957)

Returns a new dataset with each array indexed along the specified
dimension(s).

This method selects values from each array using its \_\_getitem_\_
method, except this method does not require knowing the order of
each array’s dimensions.

* **Parameters:**
  * **indexers** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – A dict with keys matching dimensions and values given
    by integers, slice objects or arrays.
    indexer can be a integer, slice, array-like or DataArray.
    If DataArrays are passed as indexers, xarray-style indexing will be
    carried out. See [Indexing and selecting data](../user-guide/indexing.html.md#indexing) for the details.
    One of indexers or indexers_kwargs must be provided.
  * **drop** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If `drop=True`, drop coordinates variables indexed by integers
    instead of making them scalar.
  * **missing_dims** (`{"raise", "warn", "ignore"}`, *default*: `"raise"`) – What to do if dimensions that should be selected from are not present in the
    Dataset:
    - “raise”: raise an exception
    - “warn”: raise a warning, and ignore the missing dimensions
    - “ignore”: ignore the missing dimensions
  * **\*\*indexers_kwargs** (`{dim: indexer, ...}`, *optional*) – The keyword arguments form of `indexers`.
    One of indexers or indexers_kwargs must be provided.
* **Returns:**
  **obj** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – A new Dataset with the same contents as this dataset, except each
  array and dimension is indexed by the appropriate indexers.
  If indexer DataArrays have coordinates that do not conflict with
  this object, then these coordinates will be attached.
  In general, each array’s data will be a view of the array’s data
  in this dataset, unless vectorized indexing was triggered by using
  an array indexer, in which case the data will be a copy.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('aa24ab1d-a707-41ab-92aa-f64a0a2b2b87','3771918a-f9c1-4b81-9579-cdbc7dd89e87','e496fe14-d738-482e-ab92-f6500b44bbc7','../lite/tree/../notebooks/index.html?path=af38613b_4d22_4b70_8be1_b882b0930acf.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dataset = xr.Dataset(
...     {
...         "math_scores": (
...             ["student", "test"],
...             [[90, 85, 92], [78, 80, 85], [95, 92, 98]],
...         ),
...         "english_scores": (
...             ["student", "test"],
...             [[88, 90, 92], [75, 82, 79], [93, 96, 91]],
...         ),
...     },
...     coords={
...         "student": ["Alice", "Bob", "Charlie"],
...         "test": ["Test 1", "Test 2", "Test 3"],
...     },
... )
```

# A specific element from the dataset is selected

```pycon
>>> dataset.isel(student=1, test=0)
<xarray.Dataset> Size: 68B
Dimensions:         ()
Coordinates:
    student         <U7 28B 'Bob'
    test            <U6 24B 'Test 1'
Data variables:
    math_scores     int64 8B 78
    english_scores  int64 8B 75
```

# Indexing with a slice using isel

```pycon
>>> slice_of_data = dataset.isel(student=slice(0, 2), test=slice(0, 2))
>>> slice_of_data
<xarray.Dataset> Size: 168B
Dimensions:         (student: 2, test: 2)
Coordinates:
  * student         (student) <U7 56B 'Alice' 'Bob'
  * test            (test) <U6 48B 'Test 1' 'Test 2'
Data variables:
    math_scores     (student, test) int64 32B 90 85 78 80
    english_scores  (student, test) int64 32B 88 90 75 82
```

```pycon
>>> index_array = xr.DataArray([0, 2], dims="student")
>>> indexed_data = dataset.isel(student=index_array)
>>> indexed_data
<xarray.Dataset> Size: 224B
Dimensions:         (student: 2, test: 3)
Coordinates:
  * student         (student) <U7 56B 'Alice' 'Charlie'
  * test            (test) <U6 72B 'Test 1' 'Test 2' 'Test 3'
Data variables:
    math_scores     (student, test) int64 48B 90 85 92 95 92 98
    english_scores  (student, test) int64 48B 88 90 92 93 96 91
```

<div id="e496fe14-d738-482e-ab92-f6500b44bbc7" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('aa24ab1d-a707-41ab-92aa-f64a0a2b2b87','e496fe14-d738-482e-ab92-f6500b44bbc7')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('aa24ab1d-a707-41ab-92aa-f64a0a2b2b87','e496fe14-d738-482e-ab92-f6500b44bbc7')">Open In Tab</button></div><div id="3771918a-f9c1-4b81-9579-cdbc7dd89e87" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`Dataset.sel`](xarray.Dataset.sel.html.md#xarray.Dataset.sel)
[`DataArray.isel`](xarray.DataArray.isel.html.md#xarray.DataArray.isel)

[Indexing](https://tutorial.xarray.dev/intermediate/indexing/indexing.html)
: Tutorial material on indexing with Xarray objects

[Indexing and Selecting Data](https://tutorial.xarray.dev/fundamentals/02.1_indexing_Basic.html)
: Tutorial material on basics of indexing
