Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I sum value in list of dataframe

I want to sum values in list that store in dataframe in column path_pair

session_id path path_pair
T01 abc [0.03, 0.09]
T02 def [0.02, 0.15, 0.26]

So the result I want to acheive can be replace same column or create a new one it something looks like this:

session_id path path_pair
T01 abc 0.12
T02 def 0.43

How can I do the script?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can apply sum function to the path_pair column:

df['path_pair_sum'] = df['path_pair'].apply(sum)

Output:

  session_id path           path_pair  path_pair_sum
0        T01  abc        [0.03, 0.09]           0.12
1        T02  def  [0.02, 0.15, 0.26]           0.43
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading