From the course: Python Data Analysis

Unlock the full course today

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

Solution: Unisex baby names

Solution: Unisex baby names - Python Tutorial

From the course: Python Data Analysis

Start my 1-month free trial

Solution: Unisex baby names

(upbeat music) - As I mentioned already, in Pandas there are often several ways to get the same result. So if your results are similar to mine, but you get them in a different way, don't worry, your solution may even be better. We'll load our data set as usual. We need to compute the total number of boys and girls for a given name. This seems a good place to use group by, which lets us segment the data before applying an aggregation, in this case, the sum of the number of babies. So we use group by over sex and name, we select the number column and we take the sum. From this list with a multi-index, we can grab the males and females respectively, using dot lock. As you see, the two indices are going to be different. Epon doesn't appear in the females. Nevertheless, we can combine the two series and pandas will align the indices for us. The results would be none where either series doesn't have an element. For…

Contents