0

I have a two-column pandas dataframe, and would like to convert the data as follows. Please advise, and thank you!

df in:
column1   column2
a         g
a         h
b         t
b         r
b         i
b         k
b         ft
c         w
c         mm
c         n
c         qq

df out:
column1   column2
a         g, h
b         t, r, i, k, ft
c         w, mm, n, qq
Dylan Moore
  • 149
  • 9

1 Answers1

0

If you haven't solved it yet:

df = df.groupby(by=['column1'], as_index=False).agg(', '.join)
print(df)

  column1         column2
0       a            g, h
1       b  t, r, i, k, ft
2       c    w, mm, n, qq
NYC Coder
  • 7,424
  • 2
  • 11
  • 24