首页 > 怎么用pandas把同一个商品的评论整合到一起?

怎么用pandas把同一个商品的评论整合到一起?

有如下一个data frame:

item_id           review_text 
B0006SIBUC        i was attracted to this 
B0009VEM4U        great snippers
...
B0006SIBUC        i am enjoying using these

我现在想把同一个商品的评价全部放在一起,大概是这样:

item_id           review_text
B0006SIBUC        i was attracted to this i am enjoying using these
B0009VEM4U        great snippers
...

请问如何可以做到这样呢?谢谢!



df = df.groupby('item_id').agg(' '.join).reset_index()
【热门文章】
【热门文章】