+ 1
How can I club repeating element in a list into one and choose the corresponding start and end time?
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 occurence and end time of last occurence. Any help will be appreciated
1 Réponse
+ 3
The following code does the job for the specific set of data you gave, but with some heavy assumptions:
- one process occurs maximum 2 times
- there are no gaps between the two occurrences
First I merged the dataframe onto itself, then modified the End column to be the maximum of the two possible endings, finally grouped by process and displaying minimum values.
My first attempts at data manipulation with pandas, so there is probably a better and more universal way to achieve this...
https://code.sololearn.com/cNca2K3g2C18/#py