Reshaping Data with pandas

Reshape DataFrames from a wide to long format, stack and unstack rows and columns, and wrangle multi-index DataFrames.
Start Course for Free
4 Hours15 Videos52 Exercises2,006 Learners
4450 XP

Create Your Free Account

By continuing you accept the Terms of Use and Privacy Policy. You also accept that you are aware that your data will be stored outside of the EU and that you are above the age of 16.

Loved by learners at thousands of companies

Course Description

Often data is in a human-readable format, but it’s not suitable for data analysis. This is where pandas can help—it’s a powerful tool for reshaping DataFrames into different formats. In this course, you’ll grow your data scientist and analyst skills as you learn how to wrangle string columns and nested data contained in a DataFrame. You’ll work with real-world data, including FIFA player ratings, book reviews, and churn analysis data, as you learn how to reshape a DataFrame from wide to long format, stack and unstack rows and columns, and get descriptive statistics of a multi-index DataFrame.

  1. 1

    Introduction to Data Reshaping

    Let's start by understanding the concept of wide and long formats and the advantages of using each of them. You’ll then learn how to pivot data from long to a wide format, and get summary statistics from a large DataFrame.
    Play Chapter Now
  2. 2

    Converting Between Wide and Long Format

    Master the technique of reshaping DataFrames from wide to long format. In this chapter, you'll learn how to use the melting method and wide to long function before discovering how to handle string columns by concatenating or splitting them.
    Play Chapter Now
  3. 3

    Stacking and Unstacking DataFrames

    In this chapter, you’ll level-up your data manipulation skills using multi-level indexing. You'll learn how to reshape DataFrames by rearranging levels of the row indexes to the column axis, or vice versa. You'll also gain the skills you need to handle missing data generated in the stacking and unstacking processes.
    Play Chapter Now
  4. 4

    Advanced Reshaping

    You'll finish by learning how to combine the reshaping process with grouping to produce quick data manipulations. Lastly, you'll discover how to transform list-like columns and handle complex nested data, such as nested JSON files.
    Play Chapter Now
Customer churn dataBooks dataFIFA players dataObesity data
Maggie MatsuiAmy Peterson
Maria Eugenia Inzaugarat Headshot

Maria Eugenia Inzaugarat

Data Scientist
Eugenia is a data scientist that enjoys not only doing machine learning projects but also telling stories with data. She obtained a Ph.D. from the University of Buenos Aires. She has taught university courses in mathematics and biology as well as online courses on Data Science. Having transitioned from an academic background into data science, Eugenia loves teaching concepts related to python programming, data science, and machine learning to help others also gain knowledge about these fields.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA