From the course: Python Data Analysis
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Yearly top ten names - Python Tutorial
From the course: Python Data Analysis
Yearly top ten names
- [Instructor] In this video, we will create yearly top 10s for male and female names. We load the data, and this time, we index it slightly differently, by sex and year only since we will need to compare all the names in the database. We now build up a query by chaining pandas methods. Getting males in 2018 is a simple matter of a multiindex.log. Then we get the most popular names by sorting our number in descending order. Head gives us a top 10. In 2018, Liam was king, followed closely by Noah. How about girls? We index sex with f, and the year is still 2018. For girls, it was Emma and Olivia. If we to build a table of the top 10 names over multiple years, we should get rid of the index with Reset Index, and select the name, Column Only. I will make this into a generic function. As I was saying, in pandas, one sees this operator chaining style often. And we can make the code clear by giving each method it's own…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.