While I think I could do this naively and poorly, I'm interested to learn a more elegant and efficient approach.
Given the following dataframe:
In [42]: df = pd.DataFrame({'flavor':['goober','tronic','goober','tronic'], 'points':[42,55,31,101]}, index=['foo','foo','bar','bar'])
In [43]: df
Out[43]:
flavor points
foo goober 42
foo tronic 55
bar goober 31
bar tronic 101
I would like to groupby the index, and convert values from flavor
column into column headers themselves, completely throwing away the flavor
and points
. So the final result would look like:
In [44]: pd.DataFrame({'goober':[42,31], 'tronic':[55,101]}, index=['foo','bar'])
Out[44]:
goober tronic
foo 42 55
bar 31 101
Thanks for any suggestions.