0
    id        POSTINGS  
     1     [9,9,9,9,9,9,9,9]
     2     [9,9,9,9,9,9,9,9]
     3     [9,0,0,0,0,0,0,0]
     4     [9,1,2,0,0,0,0,0]
     5     [9,9,9,9,9,9,9,9]
     6     [9,9,9,9,9,8,9,9]
     7     [9,9,9,9,9,9,8,9]
     8     [9,9,9,9,8,8,9,9]

Here i am trying to add a list of values in POSTING column and store the result in a new "SUM" column

Expected output

     id        POSTINGS               SUM
     1     [9,9,9,9,9,9,9,9]           56
     2     [9,9,9,9,9,9,8,8]           54
     3     [9,0,0,0,0,0,0,0]            9
     4     [9,1,2,0,0,0,0,0]           12
     5     [9,9,9,9,9,9,9,9]           56
     6     [9,9,9,9,9,8,9,9]           55
     7     [9,9,9,9,9,9,8,9]           55
     8     [9,9,9,9,8,8,9,9]           54
10
  • Is this R or Python? Commented Oct 23, 2017 at 17:02
  • @giantslovedeathmetal in python Commented Oct 23, 2017 at 17:05
  • Are you using Pandas? Commented Oct 23, 2017 at 17:05
  • Yes @GiantsLoveDeathMetal Commented Oct 23, 2017 at 17:06
  • 1
    Where is your code? Commented Oct 23, 2017 at 17:13

1 Answer 1

2

You can use the built-in sum function in apply and you'll get a column containing the sum of the list in POSTINGS:

df['SUM'] = df['POSTINGS'].apply(sum)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.