I have this panda dataframe:
System name | Rating | Count |
---|---|---|
system1 | 1 | 12 |
system1 | 2 | 156 |
system1 | 3 | 16 |
systemZ | 1 | 77 |
systemZ | 2 | 56 |
systemZ | 3 | 66 |
systemY | 1 | 99 |
systemY | 2 | 77 |
systemY | 3 | 99 |
How can I split the Rating
column so that each new column correspond to a single value in the split column. I.e., I'd like to obtain:
System name | 1 | 2 | 3 |
---|---|---|---|
system1 | 12 | 156 | 16 |
systemZ | 77 | 56 | 66 |
systemY | 99 | 77 | 99 |
How can I do this with pandas?
To create the dataframe:
import pandas as pd
df = pd.DataFrame(data={
'System name': ['system1', 'system1', 'system1', 'systemZ', 'systemZ', 'systemZ', 'systemY', 'systemY',
'systemY'],
'Rating': [1, 2, 3, 1, 2, 3, 1, 2, 3],
'Count': [12, 156, 16, 77, 56, 66, 99, 77, 99]})
print(df)