From the course: Python Data Analysis

Unlock the full course today

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

Compiling top tens

Compiling top tens - Python Tutorial

From the course: Python Data Analysis

Compiling top tens

- [Instructor] In this video, we will create yearly top tens for male and female names. We once again load the data for all years, but this time we index it slightly differently, by sex and year only. We'll keep the names as a data column. We now build up our query by chaining Pandas methods. Getting boys in 2000 is a simple matter of a multi-index lock. Then we get the most popular names by sorting the DataFrame on number in descending order. Then Head gives us the top 10. In 2023, Liam was king, followed closely by Noah. How about girls? It's Olivia and Emma. Let's build up a table to compare the top 10 names over multiple years. We only need the names, so we get rid of the index and of the number column. Working from this example, let us create a generic function to return the top 10 for each year. Now, to form a table, we collect the series as the columns as the DataFrame, labeled by year. We use a dictionary comprehension to structure the data. We see that Liam took over from…

Contents