df = pd.read_csv('movie_lens')
df1 = df.groupby([['name of movie','reviews']])
##Groupby name of the movie and put all reviews for that movie into one row..#
#name of movie.............reviews#
#titanic...................good#
#titanic...................bad#
#titanic....................great#
#superbad..................funny#
#superbad..................ok#
#superbad..................hilarious#
#How to group movies into one row and concatenate all review it a CSV that's now a dataframe.example#
#titanic....................good.bad.great#
#superbad....................funny.ok.hilarious#
答案 0 :(得分:0)
您只是按太多的东西分组。 您想要:
df1 = df.groupby(['name of movie'])['reviews'].apply(list)
或者,稍微简单一点:
df1 = df.groupby('name of movie').reviews.apply(list)
一旦您有list
条评论,
随时使用join()
或类似方法' '
来{>