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
Out[3]:
In [4]:
df.index
Out[4]:
In [5]:
# Bring the columns and place them in the index
stack = df.stack()
stack
Out[5]:
In [6]:
# The index now includes the column names
stack.index
Out[6]:
In [7]:
unstack = df.unstack()
unstack
Out[7]:
In [8]:
unstack.index
Out[8]:
In [9]:
transpose = df.T
transpose
Out[9]:
In [10]:
transpose.index
Out[10]:
No comments:
Post a Comment