I'm trying to find consecutive datetimes in Python. I got to the point where I'm able to find if each row conflicts through a loop but am stuck on how to find out if an Event was concurrent. Any suggestions on how I can accomplish this? Open to a similar approach as well!
Concurrent means when Name and Event Date is the same and the count of consecutive conflicts >= 3.
Sample Data 1:
| Event ID | Name | Date | Event Start | Event End |
|---|---|---|---|---|
| 123 | Hoper, Charles | 8/4/20 | 8/4/20 8:30 AM | 8/4/20 10:30 AM |
| 456 | Hoper, Charles | 8/4/20 | 8/4/20 8:50 AM | 8/4/20 9:20 AM |
| 789 | Hoper, Charles | 8/4/20 | 8/4/20 8:30 AM | 8/4/20 10 AM |
| 1011 | Perez, Daniel | 8/10/20 | 8/10/20 9 AM | 8/10/20 11 AM |
| 1213 | Shah, Kim | 8/5/20 | 8/5/20 12 PM | 8/5/20 1 PM |
| 1415 | Shah, Kim | 8/5/20 | 8/5/20 12:30 PM | 8/5/20 1 PM |
Current Code:
import pandas as pd
import numpy as np
df = pd.read_excel(r'[Path]\TestConcurrent.xlsx')
df['Start'] = df['Event Start']
df['End'] = df['Event End']
df['conflict'] = len(df)
#Edit from answer
df['concurrent'] = df.groupby(['Name','Event Date','conflict'])['Event ID'].transform('count').ge(3)
print(df)
Current Output:
[![enter image description here][1]][1]
Expected Output:
[![enter image description here][2]][2]