Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dataset with columns 'Start time', 'End Time', 'Process' eg

10:00, 11:00, A

11:00, 12:00, A

12:00, 13:00, B

14:00, 15:00, C

15:00, 16:00, C

I want my output as

10:00, 12:00, A

12:00, 13:00, B

14:00, 16:00, C

If you see I have clubbed the process and corresponding start and end time are also changes to start time of first occurrence and end time of last occurrence.

Any help will be appreciated


What I have tried:

Every try is going in vain. I have tried to split is into a list the sync,

Any help will be appreciated

Thanks
Posted
Updated 21-Feb-19 23:32pm

1 solution

You need to create a new set, or better still a dictionary[^], using the Process name as the key. You can then go through your dataset copying the earliest and latest times to each dictionary entry.
 
Share this answer
 
Comments
Member 14159099 22-Feb-19 5:36am    
I would be grateful if you can provide the logic/code
Richard MacCutchan 22-Feb-19 6:05am    
The basic logic is something like:
processdict = {}
# for each item in the existing dataset
if item.processname not in processdict: # this process not in the dictionary
    # add a new entry with the current times
    times = [item.starttime, item.endtime]
    processdict[item.processname] = times
else:
    # this process is in the dictionary

    # if the start time is earlier than the dictionary entry
    # replace it with this element's start time
    if item.starttime < processdict[item.processname].value[0]:
        processdict[item.processname].value[0] = item.starttime

    # as above but replacing with later end times
    if item.endtime > processdict[item.processname].value[1]:
        processdict[item.processname].value[1] = item.endtime
[no name] 7-Oct-19 2:32am    
....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900