user1673066
user1673066

Reputation: 97

Processing List Data in Pandas Columns

I have a Pandas DataFrame which looks like following

27    [A,B,C]
27    [D,E,F]
27    [G,H,I]
27    [J,K,L]
34    [M,N,O]
34    [P,Q,R]
34    [S,T,U]

I would like to aggregate all the lists with the same id. But what function would help me aggregate lists together.

Thanks

Upvotes: 2

Views: 43

Answers (1)

EdChum
EdChum

Reputation: 394041

I'm assuming your data consists of a list of characters, you can perform a groupby and call sum:

In [406]:

df.groupby('a').sum()
Out[406]:
                                       b
a                                       
27  [A, B, C, D, E, F, G, H, I, J, K, L]
34           [M, N, O, P, Q, R, S, T, U]

Upvotes: 1

Related Questions