import pandas as pd
df1 = pd.DataFrame( {"name" : ["name1", "name1", "name2", "name3", "name3" , "name3"], "item" : ["item1", "item2", "item3", "item2", "item3", "item1"] } )
df2 = df1.groupby('name')['item']
In this groupby object I have all the items for each name. I can visualise this through:
print(df2.apply(list))
and get:
name
name1 [item1, item2]
name2 [item3]
name3 [item2, item3, item1]
what I, however, would like to achieve is something like this:
name itemA itemB itemC
name1 item1 item2 NaN
name2 item3 NaN NaN
name3 item2 item3 item1
Any help is much appreciated.