简体   繁体   中英

is there way to get numbers from list

it is a weird situation. The table get id contacts. I am now get ticket trace which contains several ids here and I want to sum their contacts in total.

在此处输入图像描述

I am trying to make id and contacts into dictionary but I am having hard time to get values things I turn it into a list in each row of the trace list.

Is there any way to solve this problem?

Use DataFrame.explode and then aggregate sum:

df1 = (df.explode('ticket_trace_list')
         .groupby('ticket_trace_list', as_index=False)['Contacts'].sum())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM