convert this frame:
1, 2
----
a, g
a, a
a, j
d, b
c, e
into:
1, 2
----
a, g,a,j
d, b
c, e
what can I do, can I use groupby? what other methods?
You can use groupby with apply function join:
df.columns = list('AB')
print (df)
A B
0 a g
1 a a
2 a j
3 d b
4 c e
df = df.groupby('A')['B'].apply(','.join).reset_index()
print (df)
A B
0 a g,a,j
1 c e
2 d b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With