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?
>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