I'm trying to transform this dataset:
A B C
1 x1 a
1 x1 a
1 x1 b
2 x2 b
2 x2 a
into:
A B C1 C2 C3
1 x1 a a b
2 x2 b a null
df = pd.DataFrame({ 'A': [1, 1, 1, 2, 2],
'B': ['x1', 'x1', 'x1', 'x2', 'x2'],
'C': ['a', 'a', 'b', 'b', 'a']
})
The answer from here is somehow close but the pivot does not quite work for me. How to do a transpose a dataframe group by key on pandas?