Aggregate column of list

Viewed 107

I have the following dataframe:

Week     Name    Value
------------------------
1       [A,V,C]  [4,6,2]
2       [A,B,D]  [3,7,1]
3       [X,Y,Z]  [2,5,10]
4       [D,G,M]  [1,2,3]

How can I aggregate the list in the 'value' column? e.g.

Week     Name    Value     sum
------------------------------
1       [A,V,C]  [4,6,2]   12
2       [A,B,D]  [3,7,1]   11
3       [X,Y,Z]  [2,5,10]  17
4       [D,G,M]  [1,2,3]   6
2 Answers

You can use apply like this:

df["sum"] = df["Value"].apply(sum)

Relevant pandas docs here.

Just another way even though I found Alex's solution to be more elegant.

df['sum'] = [sum(i) for i in df['Value']]
Related