#!/usr/bin/env python # coding: utf-8 # ![Pandas Tutorial | Hedaro >](https://www.dropbox.com/s/220ncn0o5danuey/pandas-ipython-tutorials-hedaro.jpg?dl=1) # # Lesson 5 # > We will be taking a brief look at the ***stack*** and ***unstack*** functions. # In[1]: # Import libraries import pandas as pd import sys # In[2]: print('Python version ' + sys.version) print('Pandas version: ' + pd.__version__) # In[3]: # Our small data set d = {'one':[1,1],'two':[2,2]} i = ['a','b'] # Create dataframe df = pd.DataFrame(data = d, index = i) df # In[4]: df.index # In[5]: # Bring the columns and place them in the index stack = df.stack() stack # In[6]: # The index now includes the column names stack.index # In[7]: unstack = df.unstack() unstack # In[8]: unstack.index # We can also flip the column names with the index using the ***T*** (transpose) function. # In[9]: transpose = df.T transpose # In[10]: transpose.index #

This tutorial was created by HEDARO