# xarray.CFTimeIndex.value_counts

#### CFTimeIndex.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.14/site-packages/pandas/core/base.py#L1024-L1151)

Return a Series containing counts of unique values.

The resulting object will be in descending order so that the
first element is the most frequently-occurring element.
Excludes NA values by default.

* **Parameters:**
  * **normalize** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If True then the object returned will contain the relative
    frequencies of the unique values.
  * **sort** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Stable sort by frequencies when True. Preserve the order of the data
    when False.

    #### Versionchanged
    Changed in version 3.0.0: Prior to 3.0.0, the sort was unstable.
  * **ascending** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Sort in ascending order.
  * **bins** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *optional*) – Rather than count values, group them into half-open bins,
    a convenience for `pd.cut`, only works with numeric data.
  * **dropna** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Don’t include counts of NaN.
* **Returns:**
  [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) – Series containing counts of unique values.

#### SEE ALSO
`Series.count`
: Number of non-NA elements in a Series.

`DataFrame.count`
: Number of non-NA elements in a DataFrame.

`DataFrame.value_counts`
: Equivalent method on DataFrames.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('558af485-7a8e-4945-bd3d-398d1577cc90','78d83231-71c7-4ac9-9516-7689083485c2','f8302814-0749-49b6-812f-cc78abcda987','../lite/tree/../notebooks/index.html?path=9f073782_f384_4a79_b130_af6d2d304d57.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> index = pd.Index([3, 1, 2, 3, 4, np.nan])
>>> index.value_counts()
3.0    2
1.0    1
2.0    1
4.0    1
Name: count, dtype: int64
```

With normalize set to True, returns the relative frequency by
dividing all values by the sum of values.

```pycon
>>> s = pd.Series([3, 1, 2, 3, 4, np.nan])
>>> s.value_counts(normalize=True)
3.0    0.4
1.0    0.2
2.0    0.2
4.0    0.2
Name: proportion, dtype: float64
```

**bins**

Bins can be useful for going from a continuous variable to a
categorical variable; instead of counting unique
apparitions of values, divide the index in the specified
number of half-open bins.

```pycon
>>> s.value_counts(bins=3)
(0.996, 2.0]    2
(2.0, 3.0]      2
(3.0, 4.0]      1
Name: count, dtype: int64
```

**dropna**

With dropna set to False we can also see NaN index values.

```pycon
>>> s.value_counts(dropna=False)
3.0    2
1.0    1
2.0    1
4.0    1
NaN    1
Name: count, dtype: int64
```

**Categorical Dtypes**

Rows with categorical type will be counted as one group
if they have same categories and order.
In the example below, even though `a`, `c`, and `d`
all have the same data types of `category`,
only `c` and `d` will be counted as one group
since `a` doesn’t have the same categories.

```pycon
>>> df = pd.DataFrame({"a": [1], "b": ["2"], "c": [3], "d": [3]})
>>> df = df.astype({"a": "category", "c": "category", "d": "category"})
>>> df
   a  b  c  d
0  1  2  3  3
```

```pycon
>>> df.dtypes
a    category
b      str
c    category
d    category
dtype: object
```

```pycon
>>> df.dtypes.value_counts()
category    2
category    1
str         1
Name: count, dtype: int64
```

<div id="f8302814-0749-49b6-812f-cc78abcda987" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('558af485-7a8e-4945-bd3d-398d1577cc90','f8302814-0749-49b6-812f-cc78abcda987')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('558af485-7a8e-4945-bd3d-398d1577cc90','f8302814-0749-49b6-812f-cc78abcda987')">Open In Tab</button></div><div id="78d83231-71c7-4ac9-9516-7689083485c2" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
