I am hoping for some help in summarizing the dataframe detailed below into a one row summary as shown in desired output further down on the page. Many thanks in advance.
employees = {'Name of Employee': ['Mark','Mark','Mark','Mark','Mark','Mark', 'Mark','Mark','Mark','Mark','Mark','Mark','Mark'],
'Department': ['21','21','21','21','21','21', '21','21','21','21','21','21','21'],
'Team': ['2','2','2','2','2','2','2','2','2','2','2','2','2'],
'Log': ['2020-02-19 09:01:17', '2020-02-19 09:54:02', '2020-04-10 11:00:31', '2020-04-11 12:39:08', '2020-04-18 09:45:22', '2020-05-05 09:01:17', '2020-05-23 09:54:02', '2020-07-03 11:00:31', '2020-07-03 12:39:08', '2020-07-04 09:45:22', '2020-07-05 09:01:17', '2020-07-06 09:54:02', '2020-07-06 11:00:31'],
'Call Duration' : ['0.01178', '0.01736','0.01923','0.00911','0.01007','0.01206','0.01256','0.01006','0.01162','0.00733','0.01250','0.01013','0.01308'],
'ITT': ['NO','YES', 'NO', 'Follow up', 'YES','YES', 'NO', 'Follow up','YES','YES', 'NO','YES','YES']
}
df = pd.DataFrame(employees)
Desired output:
Name Dept Team Start End Weeks Total Calls Ave. Call time Sold Rejected more info
Mark 21 2 2020-02-19 2020-07-06 19.71 13 0.01207 7 4 2
The logic I am seeking to apply is (although I'm guessing there are errors in the syntax I have written below, I hope that you are still able to understand the calculations):
- Start = min date in df['Log']
- End = max date in df['Log']
- Weeks = (max date in df['log'] - min date in df['Log'])/7
- Total Calls = df['Log'].count
- Ave. Call time = (df['Call Duration'].sum)/(df['Log'].count)
- Sold = (df['ITT']=='YES').count
- Rejected = (df['ITT']=='NO').count
- more info = (df['ITT']=='Follow up').count
Try this using
pd.NamedAgg
withgroupby
:Output: