From the course: Python Data Analysis
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Comparing name popularity - Python Tutorial
From the course: Python Data Analysis
Comparing name popularity
- [Instructor] We are ready to start analyzing the data. Let's load it up. We wish to examine the changing popularity of a name. So we can index the data to make that easier. We'll use a multi-index, indexing on sex first, then name, then year. We will also sort the index. Getting the data set for any given name is, then, a simple exercise of indexing with the loc. This series is ready to plot. Notice how matplotlib automatically uses the index to set the x-axis. Mary and John had peaks in the 1920s and then again in the 1950s or '60s. It makes sense to consider the frequency of a name as a fraction of the number of babies born in a year. To get that, we use groupby to group the unindexed frame by sex and year and sum the number column. This gives us the total number of births indexed by sex and year, which is itself an interesting thing to plot. We see the baby boomers coming on stage in the '50s and '60s. We can now create a new column in all years indexed set to the relative…