From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Categorical series aggregation

Categorical series aggregation

- [Instructor] All right, so let's take a look at a few more types of aggregations we can perform on series. The methods here tend to work best on text fields or categorical fields that have values repeated throughout a series of data, but we can call them on numeric series as well. Our first method is unique. This will return an array of unique items in a series, nunique will return the number of unique items in a series, and value_counts returns a series of unique items and their frequency in our data. So here, we have our items series. Just note that coffee is repeated twice, all other values occur once. So, when we call value_counts on our item series, we can see coffee gets a count of two, tea gets a count of one, and so on. If we specify normalize equals true, we can return a percentage of the time these values occur in our data, which is often more useful than for analysis than a raw count. It depends on what we're trying to do, but usually, we'll want to say 40% of our sales…

Contents