Other techniques for reshaping data
In this chapter, we have so far covered crucial data operations such as pivoting, unpivoting/unpivoting, joining, and concatenating. There are a few other techniques you can use to reshape your data, such as .partition_by(), .transpose(), .reshape(). We’ll cover those methods in this recipe.
Getting ready
We’ll continue to use the academic_df DataFrame that we’ve become familiar with throughout this chapter.
How to do it...
Here’s how to apply those reshaping techniques:
- To partition the DataFrame into separate DataFrames by column values, we used the
.partition_by()method:academic_df.partition_by('academic_year')The preceding code will return the following output:
Figure 8.22 – The partitioned DataFrames by values in the academic_year column
- Use the
.transpose()method to flip rows and columns:academic_df.transpose(include_header=True)
The preceding...