I\'ve seen a few variations on the theme of exploding a column/series into multiple columns of a Pandas dataframe, but I\'ve been trying to do something and not really succe
You could use set_index
and unstack
In [1923]: df.set_index([df.index, 'key'])['val'].unstack()
Out[1923]:
key bar baz foo
id
2 bananas apples oranges
3 kiwis None grapes
Or, a simplified groupby
In [1926]: df.groupby([df.index, 'key'])['val'].first().unstack()
Out[1926]:
key bar baz foo
id
2 bananas apples oranges
3 kiwis None grapes