# Import Preliminaries
import pandas as pd
# Create a dataset with the index being a set of names
raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Dragoons', 'Dragoons', 'Scouts', 'Scouts', 'Scouts', 'Scouts'],
'company': ['1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd','1st', '1st', '2nd', '2nd'],
'name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze', 'Jacon', 'Ryaner', 'Sone', 'Sloan', 'Piger', 'Riani', 'Ali'],
'preTestScore': [4, 24, 31, 2, 3, 4, 24, 31, 2, 3, 2, 3],
'postTestScore': [25, 94, 57, 62, 70, 25, 94, 57, 62, 70, 62, 70]}
df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'name', 'preTestScore', 'postTestScore'], index=df.name)
df
regiment | company | name | preTestScore | postTestScore | |
---|---|---|---|---|---|
name | |||||
Miller | Nighthawks | 1st | Miller | 4 | 25 |
Jacobson | Nighthawks | 1st | Jacobson | 24 | 94 |
Ali | Nighthawks | 2nd | Ali | 31 | 57 |
Milner | Nighthawks | 2nd | Milner | 2 | 62 |
Cooze | Dragoons | 1st | Cooze | 3 | 70 |
Jacon | Dragoons | 1st | Jacon | 4 | 25 |
Ryaner | Dragoons | 2nd | Ryaner | 24 | 94 |
Sone | Dragoons | 2nd | Sone | 31 | 57 |
Sloan | Scouts | 1st | Sloan | 2 | 62 |
Piger | Scouts | 1st | Piger | 3 | 70 |
Riani | Scouts | 2nd | Riani | 2 | 62 |
Ali | Scouts | 2nd | Ali | 3 | 70 |
# Transpose the dataset, so that the index (in this case the names) are columns
df.transpose()
name | Miller | Jacobson | Ali | Milner | Cooze | Jacon | Ryaner | Sone | Sloan | Piger | Riani | Ali |
---|---|---|---|---|---|---|---|---|---|---|---|---|
regiment | Nighthawks | Nighthawks | Nighthawks | Nighthawks | Dragoons | Dragoons | Dragoons | Dragoons | Scouts | Scouts | Scouts | Scouts |
company | 1st | 1st | 2nd | 2nd | 1st | 1st | 2nd | 2nd | 1st | 1st | 2nd | 2nd |
name | Miller | Jacobson | Ali | Milner | Cooze | Jacon | Ryaner | Sone | Sloan | Piger | Riani | Ali |
preTestScore | 4 | 24 | 31 | 2 | 3 | 4 | 24 | 31 | 2 | 3 | 2 | 3 |
postTestScore | 25 | 94 | 57 | 62 | 70 | 25 | 94 | 57 | 62 | 70 | 62 | 70 |