From the course: Advanced Pandas

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Mapping variables into groups

Mapping variables into groups

From the course: Advanced Pandas

Start my 1-month free trial

Mapping variables into groups

- [Instructor] Sure enough, pandas has loads of capabilities to create categories, labels and buckets within your datasets, all with the goal of deriving insights from your qualitative data. Let's investigate a few options. First, we'll create a data frame for counts of salmon on the Skokomish river in Washington state. Here we have species of salmon, where the population is from and they count recorded for those fish. One really handy function in Pandas is called cut. This allows you to create bins for numerical data, then apply those to your data frame. We're going to create bins of 2000 for our count data. Notice here, I important NumPy to make use of NumPy dot inf or infinity, for the top end of our buckets. We label each of the buckets as well, from low return to high return. Next, we create a new column in our data frame called count category. And we pass the count column along with the bins and the labels we've…

Contents