This is my first post so please be kind :P
I am currently working on pandas in python 3.7.
The aim is to reshape a datraframa by dissolving the "subclass" methods (M1, M2, Mn).
This is my starting point:
(0, 'gas', 'M1', 0.50)
(0, 'gas', 'M2', 0.49)
(1, 'coal', 'M1', 0.80)
(1, 'coal', 'M2', 0.81)
(2, 'wind', 'M1', 0.34)
(2, 'wind', 'M2', 0.94)
From following source code data:
[{'ID': 0,'type': 'gas', 'Method': 'M1',
'Score': 0.50},{'ID': 0,'type': 'gas', 'Method': 'M2',
'Score': 0.80},{'ID': 1,'type': 'coal', 'Method': 'M1',
'Score': 0.81},{'ID': 1,'type': 'coal', 'Method': 'M2',
'Score': 0.49},{'ID': 2,'type': 'wind', 'Method': 'M1',
'Score': 0.34},{'ID': 2,'type': 'wind', 'Method': 'M2',
'Score': 0.94}]
which gets loaded into a pandas dataframe by:
df = pd.DataFrame(results, columns=["ID","type", "Method", "Score"])
creating following structure:
ID type Method Score
0 gas M1 0,50
0 gas M2 0,49
1 coal M1 0,80
1 coal M2 0,81
2 wind M1 0,34
2 wind M2 0,94
Unltimately I would like to achive the following format:
ID type M1 M2
0 gas 0,50 0,49
1 coal 0,80 0,81
2 wind 0,34 0,94
Since the amount of methods can vary, a simple cut and paste will probably not do the job. Any feedback would be helpful! Thanks :)