0

I want merge words with the same value in dataframe into one, stick the words next to each other at once

ex)

en ko
acrania a
acrania b
acrania c
acrania d

=>

en ko
acrania a,b,c,d

I want to make it in the form above.please help me

I was only able to remove duplicates in Excel, and it is too difficult for me to paste them sideways after removing duplicates.

이승우
  • 5
  • 2
  • 1
    Does this answer your question? [Concatenate strings from several rows using Pandas groupby](https://stackoverflow.com/questions/27298178/concatenate-strings-from-several-rows-using-pandas-groupby) – Tom Oct 27 '22 at 02:47

1 Answers1

0

Given your dataframe looks like this

df = {'en': ['acrania', 'acrania', 'acrania', 'acrania'], 'ko': ['a', 'b', 'c', 'd']}

Simply use groupby

df = df.groupby('en')['ko'].apply(','.join).reset_index()

Output:

        en       ko
0  acrania  a,b,c,d

Hope this helps.

Andrew
  • 176
  • 1
  • 14