This chapter marks the midpoint of the book and shifts from short, topic-focused exercises to a larger integrative project. The goal is to reinforce pandas fluency through practice, reminding readers that mistakes and forgotten syntax are normal and that skill grows gradually through repetition. Rather than treating pandas as a set of isolated tricks, the chapter encourages using multiple techniques together to explore real survey data.
The first half of the project uses the 2020 Python Developer Survey. Readers load the CSV into a data frame, then reshape its many flat column names into a two-level multi-index so the data is easier to navigate. Some columns are grouped under a general category, while most are split at the final period in the name. After sorting the columns, the chapter asks questions about the most popular IDEs, other languages used by Python developers, where respondents live, how much Python experience they have, and which countries have the most experienced developers in both absolute and relative terms.
The second half turns to the 2021 Stack Overflow survey. Readers analyze average salary by employment type, then build pivot tables comparing salary by education level and country, including a restricted view of OECD countries. The chapter then filters the data down to respondents who use Python, cleans missing and awkward experience values, converts years of coding into integers, and bins those into experience categories. Finally, it compares the experience distribution in the Stack Overflow sample with the Python survey, while emphasizing that results from different surveys should be interpreted carefully because the questions and populations are not identical.
Turning a single index row into a multi-index
Summary
Whew! This was a big, long exercise, meant to help you integrate and use many of the ideas and techniques we’ve discussed in this book so far. Of course, there are many pieces of pandas that we didn’t use in this project—but to be honest, it’s a rare project that uses all the capabilities pandas has to offer. That said, we did a lot of things here: loading and cleaning data, joining data frames, analyzing data, and even comparing different data sets and thinking critically about how trustworthy they are. If you felt comfortable with all the techniques in this project, I’d say you’re well on your way to internalizing the way pandas does things and using it productively in your projects.
FAQ
What is the main goal of Chapter 8’s midway project?
The chapter asks you to apply several pandas skills together in one small project, using survey data from Python developers and Stack Overflow to answer real analysis questions.Which two datasets are used in the project?
The project uses the 2020 Python Developer Survey data from JetBrains and the 2021 Stack Overflow survey data.Why does the chapter recommend creating a MultiIndex for the Python survey columns?
Because the CSV has many flat column names that actually imply hierarchy. A MultiIndex makes the data easier to understand and work with by grouping related columns together.How are column names like other.lang.Java converted into a MultiIndex?
They are split at the final period using str.rsplit('.', 1), producing tuples such as ('other.lang', 'Java'), which are then passed to pd.MultiIndex.from_tuples.Which columns are placed under the top-level label general?
A set of survey fields such as age, country.live, employment.status, python.years, and several others are grouped under general instead of being split by periods.How do you find the 10 most popular Python IDEs in the Python survey?
Use the('ide', 'main') column, apply value_counts(), and then keep the top 10 results with head(10).How do you determine the most commonly used non-Python programming languages?
Look at theother.lang columns, count non-null entries with count(), sort descending with sort_values(ascending=False), and take the top 10.How is the proportion of Python developers by experience level calculated in the Python survey?
Usevalue_counts(normalize=True) on ('general', 'python.years') to get the fraction of respondents in each experience category.How does the chapter compare salary by employment type in the Stack Overflow survey?
It groups byEmployment and computes the mean of ConvertedCompYearly, which shows average salary for full-time employees, contractors, freelancers, and others.How is Stack Overflow experience categorized for comparison with the Python survey?
Rows with missingYearsCode are removed, text values like Less than 1 year and More than 50 years are converted to numbers, and then pd.cut creates the experience bins: Less than 1 year, 1-2 years, 3-5 years, 6-10 years, and 11+ years.
Pandas Workout ebook for free