简体   繁体   中英

Pandas groupby on two column and create new column in excel based on result

I have excel file which i am reading in jupyter.

It has three column: 1) Webinar ID : (66 unique value) 2) Email : email id of participants (which can log out in session and join again so duplicate email id for same webinar id) 3) Time in session (minutes) : participant present in session, since he might log out and again log in, there are multiple entries.

Code Used: data_group = data.groupby(['Webinar ID', 'Email'])

data_group['Time in Session (minutes)'].sum()

I want to create new column in excel and store Sum of Time in Session (minutes) information for same - Webinar ID and Email

Thanks!!

IIUC, you wish to create a new column with the sum of times per webinar group and email.

Let's use groupby with transform :

data['Sum Session Minutes'] = (data.groupby(['Webinar ID','Email'])['Time in Session (minutes)']
                                   .transform('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