I have a raw data exported and transformed a bit from salesforce below;
df = pd.DataFrame(columns=['contact_start','name', 'aht'],
data=[['2021-09-27 09:58:00','Venus','180'],
['2021-09-27 10:00:00','Venus','240'],
['2021-09-27 11:05:00','Venus','60'],
['2021-09-27 10:55:00','Mars','30'],
['2021-09-27 10:56:00','Mars','30']])
using these codes below
df["contact_start"] = pd.to_datetime(df["contact_start"], format = "%Y-%m-%d %H:%M:%S",errors='coerce')
df["date"] = df["contact_start"].dt.strftime('%Y-%m-%d')
df['aht']=pd.to_datetime(df["aht"], unit='s').dt.strftime("%H:%M:%S")
df['contact_finish'] = pd.to_timedelta(df['aht']) + pd.to_datetime(df['contact_start'])
df['contact_finish'] = df['contact_finish'].astype('datetime64[s]')
I transform this into :
but my final goal is to deal with overlapping and I ran out of ideas how to make it happen.
the outcome should be like this in below:
df = pd.DataFrame(columns=['date','name', 'total_duration_sec'],
data=[['2021-09-27','Venus','420'],
['2021-09-27','Mars','60']])
I guess it looks simple but in fact it is really not. I would appreciate any help.
Edit : I do not know how to put a more meaningful data in python so i uploaded a sample data file (3kb csv)


