# xarray.IndexVariable.count

#### IndexVariable.count(dim=None, \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/namedarray/_aggregations.py#L28-L77)

Reduce this NamedArray’s data by applying `count` along some dimension(s).

* **Parameters:**
  * **dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), `Iterable` of `Hashable`, `"..."` or [`None`](https://docs.python.org/3/builtins/constants.html#None), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Name of dimension[s] along which to apply `count`. For e.g. `dim="x"`
    or `dim=["x", "y"]`. If “…” or None, will reduce over all dimensions.
  * **\*\*kwargs** (`Any`) – Additional keyword arguments passed on to the appropriate array
    function for calculating `count` on this object’s data.
    These could include dask-specific kwargs like `split_every`.
* **Returns:**
  **reduced** (`NamedArray`) – New NamedArray with `count` applied to its data and the
  indicated dimension(s) removed

#### SEE ALSO
[`pandas.DataFrame.count`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.count.html#pandas.DataFrame.count), [`dask.dataframe.DataFrame.count`](https://docs.dask.org/en/latest/generated/dask.dataframe.DataFrame.count.html#dask.dataframe.DataFrame.count), [`Dataset.count`](xarray.Dataset.count.html.md#xarray.Dataset.count), [`DataArray.count`](xarray.DataArray.count.html.md#xarray.DataArray.count)

[Aggregation](../user-guide/computation.html.md#agg)
: User guide on reduction or aggregation operations.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('029f23d3-2432-4529-85bb-bfb03748b060','e68d2e1d-cab7-4f4e-af9c-e6193e09b50d','82b447fd-8656-480f-b40c-ae025ab8f985','../lite/tree/../notebooks/index.html?path=100218bd_b50b_4e60_9f43_0fec060ab2fd.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> from xarray.namedarray.core import NamedArray
>>> na = NamedArray("x", np.array([1, 2, 3, 0, 2, np.nan]))
>>> na
<xarray.NamedArray (x: 6)> Size: 48B
array([ 1.,  2.,  3.,  0.,  2., nan])
```

```pycon
>>> na.count()
<xarray.NamedArray ()> Size: 8B
array(5)
```

<div id="82b447fd-8656-480f-b40c-ae025ab8f985" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('029f23d3-2432-4529-85bb-bfb03748b060','82b447fd-8656-480f-b40c-ae025ab8f985')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('029f23d3-2432-4529-85bb-bfb03748b060','82b447fd-8656-480f-b40c-ae025ab8f985')">Open In Tab</button></div><div id="e68d2e1d-cab7-4f4e-af9c-e6193e09b50d" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
