7 Advanced grouping, joining, and sorting

 

In the previous chapter, we used three of the central tools in pandas: grouping data across different columns, joining multiple data frames, and sorting a data frame by its index or one or more columns. As we saw, each of these techniques gives us a powerful way to manipulate our data into a form that allows for better understanding and interpretation.

In this chapter, we’ll explore deeper ways to use these techniques, both by themselves and together. We’ll turn multiple CSV files into a single data frame, we’ll group and sort by multiple columns, and we’ll use the filter method to keep and reject rows based on group properties. After going through the exercises in this chapter, you’ll have an even stronger understanding of these techniques, how they can help you solve problems, and when it’s appropriate to use them.

Exercise 32 Multicity temperatures

Working it out

Solution

Beyond the exercise

Exercise 33 SAT scores, revisited

Working it out

Solution

Beyond the exercise

Exercise 34 Snowy, rainy cities

Working it out

Solution

Beyond the exercise

Exercise 35 Wine scores and tourism spending

Working it out

Solution

Beyond the exercise

Summary