How to group all review texts of each item together with python-pandas? -


given such data frame:

item_id           review_text  b0006sibuc        attracted  b0009vem4u        great snippers ... b0006sibuc        enjoying using these 

i'd combine review texts of each items. resulting data frame should be:

item_id           review_text b0006sibuc        attracted enjoying using these b0009vem4u        great snippers ... 

how can that? thank in advance!

use groupby/agg, , ' '.join join strings in each group one:


for example,

in [19]: df = pd.dataframe({'item_id':['a', 'b', 'a'], 'foo':['x','y','z']})  in [20]: df.groupby('item_id').agg(' '.join).reset_index() out[20]:    item_id  foo 0        x z 1       b    y 

Comments