There is a very popular S.O. question regarding groupby to dataframe see here. Unfortunately, I do not think this particular use case is the most useful.
Suppose you have what could be a hierarchical dataset in a flattened form:
e.g.
key val
0 'a' 2
1 'a' 1
2 'b' 3
3 'b' 4
what I wish to do is convert that dataframe to this structure
'a' 'b'
0 2 3
1 1 4
I thought this would be as simple as
pd.DataFrame(df.groupby('key').groups)
but it is not.
So how can I make this transformation?