I have a dataframe like this:
I am trying to reshape it like this:
For the life of me, I can't get this right.
I thought using df.pivot_table
would work, but it did some sort of averaging of the scores.
I've search SO and can't find a similar question. Most reshaping questions don't want to make a dataset wide.
Any advice is appreciated.
df = [ {'id' : '1', 'score_type': 'test_01', 'score': 1},
{'id' : '1', 'score_type': 'test_02', 'score': 2},
{'id' : '1', 'score_type': 'test_03', 'score': 3},
{'id' : '1', 'score_type': 'test_04', 'score': 4},
{'id' : '2', 'score_type': 'test_01', 'score': 5},
{'id' : '2', 'score_type': 'test_02', 'score': 6},
{'id' : '2', 'score_type': 'test_03', 'score': 7},
{'id' : '2', 'score_type': 'test_04', 'score': 8}
]
df = pd.DataFrame(df)
df = df[['id', 'score_type', 'score']]
df