# xarray.NamedArray.count

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

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('50ccfab5-5155-4f5e-826c-3d6c63275d4d','c0068f57-1f5f-4467-8a99-def4bf80de07','88b8d128-7f21-462d-a676-59b6afa09ac4','../lite/tree/../notebooks/index.html?path=8d698207_c84b_4144_8b39_e8761f9cfefb.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="88b8d128-7f21-462d-a676-59b6afa09ac4" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('50ccfab5-5155-4f5e-826c-3d6c63275d4d','88b8d128-7f21-462d-a676-59b6afa09ac4')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('50ccfab5-5155-4f5e-826c-3d6c63275d4d','88b8d128-7f21-462d-a676-59b6afa09ac4')">Open In Tab</button></div><div id="c0068f57-1f5f-4467-8a99-def4bf80de07" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
