串联分组字符串

时间:2018-12-21 16:08:57

标签: pandas

我有一个类似于以下内容的分组字符串df:

chat_type         message
Account           My Account is missing money
Account           I need to update my account
Benefits          My benefits suck
Benefits          Where is my benefit check

所需的输出

chat_type          message
Account            My Account is missing money I need to update my account
Benefits           My benefits suck Where is my benefits check

我尝试的

解决方案
dfn = df.groupby('chat_type')['message'].join()

返回此消息

AttributeError: 'SeriesGroupBy' object has no attribute 'join'

1 个答案:

答案 0 :(得分:1)

尝试:

df=df.groupby('chat_type')['message'].apply(' '.join).reset_index()