From the course: pandas Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reshaping

Reshaping - pandas Tutorial

From the course: pandas Essential Training

Start my 1-month free trial

Reshaping

- [Instructor] We're going to look at two new functions that are very helpful, especially when used in conjunction with group by. The stack function allows you to move the inner columns to the rows for the dataframe and the unstack function does the reverse. The next slide has a helpful visualization that will help you understand what both the stack and the unstack functions do. The stack function helps you to reshape the dataframe. The table on the top left is the original dataframe. What I have captured here are the athletes that's both the male and female athletes that won medals at the Beijing 2008 Olympics in both the 100 meters and the 200 meters athletic events and which countries they represented. Let's head over to the Jupyter Notebook and create this table, so let's import pandas as pd, import our dataset into the dataframe. Let's take a look at the athletes that took part in the 100 meters or the 200 meters track event, so we want to use our dataframe and remember that…

Contents