1.8 Assessing Categorical Data
When assessing categorical variables within a dataset, the value_counts() function from pandas is a very handy item to have in your toolkit. This function indicates the number of instances for each category. By default, it presents them in ranked order, from highest to lowest, as shown below:

After consulting the dataset description, we can see from the results above that poetry readings were the most common type of special event that season, with 29 such events held. The second most common type was “No Special Event.” Country music and live comedy shows were tied with 15 events each, followed by children’s events and rock music, respectively.
Repeatedly needing to check with the dataset description to know which numbers correspond to which event types could be annoying, though! Renaming the special events with descriptive labels will make them easier for an analyst to keep track of, and will also make any subsequent analysis easier to convey to an audience.
In the code steps shown below, pandas’ cat.rename_categories() is used with a mapping of key-value pairs, in the form of a Python dictionary5, to convert the original labels (the numbers) into the new, more descriptive format.

Calling the value_counts() function once again returns the same results, in terms of the numbers of occurrences for each special event. Now, however, the labels are much more descriptive, easier to understand and keep track of.
As indicated by the second example shown below, adding the normalize=True parameter to the value_counts() function causes the values to appear as proportions of the whole, rather than as integer values.

5 While ‘dictionary’ may seem like a strange term for a data type, we assure you that this is really a thing! You can think of a Python dictionary as an unordered set of key-value pairs. Inside the curly braces, the keys precede the values, and are separated from the values by a colon. The values can be repeated, but each key must be unique. You can read more about Python dictionaries in the official Python 3 documentation.