Concatenate strings from several rows using Pandas groupby

后端 未结 4 1921
误落风尘
误落风尘 2020-11-22 03:17

I want to merge several strings in a dataframe based on a groupedby in Pandas.

This is my code so far:

import pandas as pd
from io import StringIO

         


        
4条回答
  •  春和景丽
    2020-11-22 04:16

    The answer by EdChum provides you with a lot of flexibility but if you just want to concateate strings into a column of list objects you can also:

    output_series = df.groupby(['name','month'])['text'].apply(list)

提交回复
热议问题