# xarray.Variable.count

#### Variable.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('8bcf92a0-a625-4537-9c20-2486d2883ea7','f7266a6f-70f0-4120-8fd1-9f2c16d9f474','694de5e4-3542-421c-b664-2837d11a9c12','../lite/tree/../notebooks/index.html?path=d23d42fa_9864_4bee_8aac_a141ab6beaff.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="694de5e4-3542-421c-b664-2837d11a9c12" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('8bcf92a0-a625-4537-9c20-2486d2883ea7','694de5e4-3542-421c-b664-2837d11a9c12')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('8bcf92a0-a625-4537-9c20-2486d2883ea7','694de5e4-3542-421c-b664-2837d11a9c12')">Open In Tab</button></div><div id="f7266a6f-70f0-4120-8fd1-9f2c16d9f474" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
