Reshaping Data with pandas
Learn to pivot, melt, stack and unstack pandas DataFrames, work with multi-level indexes, and flatten list-like columns and nested JSON data.
Data arranged for people to read is often in the wrong shape for analysis. Reshaping DataFrames in pandas closes that gap. You convert tables between wide and long layouts, move index levels between rows and columns, split or join string columns, and flatten list-like and nested JSON data, practicing on FIFA player ratings, book reviews and other real datasets.
What You Will Achieve
- Decide whether an analysis needs a wide or a long layout and convert a DataFrame in either direction
- Split or concatenate string columns so their values are ready to analyze
- Shift row index levels onto the column axis and back, then deal with the missing values the move creates
- Expand list-like columns and read nested JSON files into a usable DataFrame
Program Overview
Wide and Long Data Formats
Sets out when each layout helps, then the pandas tools that turn a DataFrame long or wide and tidy its text fields.
- Pivot method and pivot tables
- Summary statistics on a large DataFrame
- Melt and the wide to long function
- Concatenating and splitting string columns
Stacking and Unstacking with Multi-Level Indexes
Uses multi-level indexing to rearrange levels between the row index and the column axis.
- Stacking and unstacking rows and columns
- Working with multiple index levels
- Handling missing data after stacking or unstacking
Grouping and Nested Data
Combines reshaping with grouping for quick manipulations, then turns list-like and nested values into regular columns.
- Reshaping combined with grouping
- Transforming list-like columns
- Reading nested JSON data into a DataFrame
- Un-nesting nested data columns
Certificate Awarded (Paid)
Job Outlook
Reshaping tables is routine work for data analysts and data scientists using Python, wherever exported tables or nested JSON files must be put into a workable shape before analysis begins.
Good for: Analysts working in pandas who regularly face tables or nested JSON files that need rearranging before any analysis can start.
Keep in mind: Each chapter practices on its own datasets, such as FIFA ratings, book reviews and call records, so you carry each method over to your own files yourself.
Bottom line: A focused run of exercises on pandas reshaping methods that carries through to the awkward cases of multi-level indexes and nested JSON.
Frequently Asked Questions
What separates wide data from long data?
In a wide table each observation sits on one row and its variables spread across many columns. A long table moves those variables into rows instead. The lessons set out the advantages of each layout and practice converting a DataFrame both ways.
Which pandas methods do the lessons use for reshaping?
The early chapters work with pivot, pivot tables, melt and the wide_to_long function. Later chapters use stacking and unstacking on multi-level indexes, combine reshaping with grouping, and transform list-like columns and nested data so each value ends up in its own column.
What kind of data do the exercises work with?
The practice data includes FIFA player ratings, book reviews and churn analysis data. Later chapters also work with call records and nested data on movies and birds, so each reshaping method is tried on a different real-world table.


There are no reviews yet.