w3resource

Pandas Series: value_counts() function

Series containing counts of unique values in Pandas

The value_counts() function is used to get 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.

Syntax:

Series.value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True)
Pandas Series value_count image

Parameters:

Name Description Type/Default Value Required / Optional
normalize If True then the object returned will contain the relative frequencies of the unique values. boolean
Default Value: False
Required
sort Sort by frequencies. boolean
Default Value: True
Required
ascending Sort in ascending order. boolean
Default Value: False
Required
bins IRather than count values, group them into half-open bins, a convenience for pd.cut, only works with numeric data. integer Optional
dropna Don’t include counts of NaN. boolean
Default Value: True
Required

Returns: Series

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts