From the course: Python Data Analysis

Unlock the full course today

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

Solution: Unisex names

Solution: Unisex names - Python Tutorial

From the course: Python Data Analysis

Solution: Unisex names

- [Instructor] We need to find the top unisex names in 2023. Doing so will require a decent amount of pandas manipulations, which I'm sure you could achieve in different ways. What I'm going to show you is just one possibility. First, setting an index of sex and name will help us. Next, we separate the boys and the girls. You may have guessed that a merge operation will give us records for unisex names. We need to rename the two columns with a number of names that come from the left and the right data frames. Next, we compute the total frequency of the names, as well as the boys to girls ratio. This will be our factor to condition. You see that we use a logical and to combine the two pieces. We use the resulting Boolean array to down select the data frame. Last, we sort. And we skim off the top. Let's try this out. Oops. What did I do wrong here? I see. I need to apply my condition on the ratio of the numbers and not on the entire data frame. Here we go.

Contents