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.