# xarray.DataArray.rank

#### DataArray.rank(dim, , pct=False, keep_attrs=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L5555-L5598)

Ranks the data.

Equal values are assigned a rank that is the average of the ranks that
would have been otherwise assigned to all of the values within that
set.  Ranks begin at 1, not 0. If pct, computes percentage ranks.

NaNs in the input array are returned as NaNs.

The bottleneck library is required.

* **Parameters:**
  * **dim** (`Hashable`) – Dimension over which to compute rank.
  * **pct** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If True, compute percentage ranks, otherwise compute integer ranks.
  * **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 dataset’s attributes (attrs) will be copied from
    the original object to the new one.  If False (default), the new
    object will be returned without attributes.
* **Returns:**
  **ranked** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – DataArray with the same coordinates and dtype ‘float64’.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('eb39edfd-9dff-46d8-a651-b98a9e7582e8','8a471fac-e721-484e-be51-a38b24dd1e7a','2e7df366-b27b-4df9-b308-d5303c5c3993','../lite/tree/../notebooks/index.html?path=a16e3449_e9bc_4ba1_8e3b_7d97cb0f1e1b.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> arr = xr.DataArray([5, 6, 7], dims="x")
>>> arr.rank("x")
<xarray.DataArray (x: 3)> Size: 24B
array([1., 2., 3.])
Dimensions without coordinates: x
```

<div id="2e7df366-b27b-4df9-b308-d5303c5c3993" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('eb39edfd-9dff-46d8-a651-b98a9e7582e8','2e7df366-b27b-4df9-b308-d5303c5c3993')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('eb39edfd-9dff-46d8-a651-b98a9e7582e8','2e7df366-b27b-4df9-b308-d5303c5c3993')">Open In Tab</button></div><div id="8a471fac-e721-484e-be51-a38b24dd1e7a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
