Stage 1 · Lesson 7 of 7
Reshaping between long and wide
Wide data has one column per month or category, which is how people like to read tables. Long data has observation and a column saying which month or category it belongs to, which is what plotting libraries and models usually want.
Converting between them is a daily step. uses melt to go long and pivot or pivot_table to go wide; tidyr uses pivot_longer and pivot_wider. Before reshaping, decide what one row should represent in the result.
Common trappivoting wide when two rows share the same row and column labels: pandas pivot raises an error, pivot_table quietly averages them, and tidyr warns and packs them into lists, so check for duplicates first.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Solid Python basics first: data types, collections, functions and files, the ground pandas stands on
- CourseFreeKaggle Learn
Kaggle · Beginner
Free: the Python and Pandas courses, short lessons with exercises that run in the browser