Concatenate strings from several rows using Pandas groupby
You can groupby the ‘name’ and ‘month’ columns, then call transform which will return data aligned to the original df and apply a lambda where we join the text entries: In [119]: df[‘text’] = df[[‘name’,’text’,’month’]].groupby([‘name’,’month’])[‘text’].transform(lambda x: ‘,’.join(x)) df[[‘name’,’text’,’month’]].drop_duplicates() Out[119]: name text month 0 name1 hej,du 11 2 name1 aj,oj 12 4 name2 fin,katt 11 6 … Read more