# xarray.Dataset.idxmax

#### Dataset.idxmax(dim=None, \*, skipna=None, fill_value=<NA>, keep_attrs=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L9497-L9602)

Return the coordinate label of the maximum value along a dimension.

Returns a new Dataset named after the dimension with the values of
the coordinate labels along that dimension corresponding to maximum
values along that dimension.

In comparison to [`argmax()`](xarray.Dataset.argmax.html.md#xarray.Dataset.argmax), this returns the
coordinate label while [`argmax()`](xarray.Dataset.argmax.html.md#xarray.Dataset.argmax) returns the index.

* **Parameters:**
  * **dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *optional*) – Dimension over which to apply idxmax.  This is optional for 1D
    variables, but required for variables with 2 or more dimensions.
  * **skipna** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, skip missing values (as marked by NaN). By default, only
    skips missing values for `float`, `complex`, and `object`
    dtypes; other dtypes either do not have a sentinel missing value
    (`int`) or `skipna=True` has not been implemented
    (`datetime64` or `timedelta64`).
    If False, NaN is treated as the maximum like in
    [`numpy.argmax()`](https://numpy.org/doc/stable/reference/generated/numpy.argmax.html#numpy.argmax), so the label of the first NaN is returned.
  * **fill_value** (`Any`, *default*: `NaN`) – Value to be filled in case all of the values along a dimension are
    null.  By default this is NaN.  The fill value and result are
    automatically converted to a compatible dtype if possible.
    Ignored if `skipna` is False.
  * **keep_attrs** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, the attributes (`attrs`) of the coordinate are copied to
    the result. If False, the result is returned without attributes.
* **Returns:**
  **reduced** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – New Dataset object with idxmax applied to its data and the
  indicated dimension removed.

#### SEE ALSO
[`DataArray.idxmax`](xarray.DataArray.idxmax.html.md#xarray.DataArray.idxmax), [`Dataset.idxmin`](xarray.Dataset.idxmin.html.md#xarray.Dataset.idxmin), [`Dataset.max`](xarray.Dataset.max.html.md#xarray.Dataset.max), [`Dataset.argmax`](xarray.Dataset.argmax.html.md#xarray.Dataset.argmax)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('d00ffb03-6c81-473d-8bef-d6802823e739','f942ba29-656d-4c85-b383-86474849c219','183b2da3-22cd-4b38-aaad-5f18532d8174','../lite/tree/../notebooks/index.html?path=63c9cee0_c09a_41f5_bfb3_ca50da0c27fd.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> array1 = xr.DataArray(
...     [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]}
... )
>>> array2 = xr.DataArray(
...     [
...         [2.0, 1.0, 2.0, 0.0, -2.0],
...         [-4.0, np.nan, 2.0, np.nan, -2.0],
...         [np.nan, np.nan, 1.0, np.nan, np.nan],
...     ],
...     dims=["y", "x"],
...     coords={"y": [-1, 0, 1], "x": ["a", "b", "c", "d", "e"]},
... )
>>> ds = xr.Dataset({"int": array1, "float": array2})
>>> ds.max(dim="x")
<xarray.Dataset> Size: 56B
Dimensions:  (y: 3)
Coordinates:
  * y        (y) int64 24B -1 0 1
Data variables:
    int      int64 8B 2
    float    (y) float64 24B 2.0 2.0 1.0
>>> ds.argmax(dim="x")
<xarray.Dataset> Size: 56B
Dimensions:  (y: 3)
Coordinates:
  * y        (y) int64 24B -1 0 1
Data variables:
    int      int64 8B 1
    float    (y) int64 24B 0 2 2
>>> ds.idxmax(dim="x")
<xarray.Dataset> Size: 40B
Dimensions:  (y: 3)
Coordinates:
  * y        (y) int64 24B -1 0 1
Data variables:
    int      <U1 4B 'b'
    float    (y) <U1 12B 'a' 'c' 'c'
```

<div id="183b2da3-22cd-4b38-aaad-5f18532d8174" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('d00ffb03-6c81-473d-8bef-d6802823e739','183b2da3-22cd-4b38-aaad-5f18532d8174')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('d00ffb03-6c81-473d-8bef-d6802823e739','183b2da3-22cd-4b38-aaad-5f18532d8174')">Open In Tab</button></div><div id="f942ba29-656d-4c85-b383-86474849c219" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
