You can merge df1
(top-left) with a .groupby
version of df2
(top-right):
df3 = df1.merge(df2.groupby('Business_id')['Review_text'].apply(list).reset_index(),
how='left', on='Business_id').rename({'Review_text':'All_reviews'}, axis=1)
Out[1]:
Business_id category star Review_count All_reviews
0 1 shopping 3.5 3 [Text_1, Text_2, Text_4]
1 2 restaurant 5.0 1 [Text_3, Text_5]
2 3 Home services 4.0 6 NaN
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.