Pandas Series.value_counts()

The value_counts() function returns a Series that contain counts of unique values. It returns an object that will be in descending order so that its first element will be the most frequently-occurred element.

By default, it excludes NA values.

Syntax

Parameters

  • normalize: If it is true, then the returned object will contain the relative frequencies of the unique values.
  • sort: It sort by the values.
  • ascending: It sort in the ascending order.
  • bins: Rather than counting the values, it groups them into the half-open bins that provide convenience for the pd.cut, which only works with numeric data.
  • dropna: It does not include counts of NaN.

Returns

It returns the counted series.

Example1

Output

1.0    2
3.0    1
2.0    1
dtype: int64

Example2

Output

1.0    0.50
3.0    0.25
2.0    0.25
dtype: float64

Example3

Output

(0.997, 2.0]    4
(2.0, 3.0]        1
dtype: int64

Example4

Output

2.0     2
1.0     2
NaN   1
3.0     1
dtype: int64





Latest Courses