I'm having trouble counting the total Record IDs where Start and End for each row are consecutive. Consecutive means when a row starts before the previous row ends and Name == Name. Record IDs 1-3 are consecutive because they overlap and have consecutive start/end datetimes.
I only want to display TRUE where total consecutive conflicts > = 3, else FALSE.
import pandas as pd
import io
#SAMPLE DATA 1 DF
df = pd.read_csv(io.StringIO("""
Record ID;Record Name;Record Start;Record End
1;SMITH, JOHN;10/20/20 8:00 AM;10/20/20 9:30 AM
2;SMITH, JOHN;10/20/20 9:20 AM;10/20/20 10:30 AM
3;SMITH, JOHN;10/20/20 10:20 AM;10/20/20 11:00 AM
4;SMITH, JOHN ;10/20/20 1:00 AM;10/20/20 2:15 PM
5;SMITH, JOHN;10/20/20 2:00 PM;10/20/20 4:00 PM
"""),sep=';')
# SAMPLE DATA 2 DF
df = pd.read_csv(io.StringIO("""
Record ID;Record Name;Record Start;Record End
1;SMITH, JOHN;10/4/20 8:00 AM;10/20/20 9:30 AM
2;SMITH, JOHN;10/4/20 9:20 AM;10/20/20 10:30 AM
3;SMITH, JOHN;10/4/20 11:20 AM;10/20/20 12:00 PM
4;SMITH, JOHN ;10/4/20 1:00 PM;10/20/20 2:15 PM
5;SMITH, JOHN;10/4/20 3:15 PM;10/20/20 4:00 PM
"""),sep=';')
df['Start'] = df['Record Start']
df['End'] = df['Record End']
df['overlap?'] = False
print(df)
Expected Output for Sample Data 1:
Record ID Record Name ... overlap? total records consec >=3?
0 1 SMITH, JOHN ... True True
1 2 SMITH, JOHN ... True True
2 3 SMITH, JOHN ... True True
3 4 SMITH, JOHN ... True False
4 5 SMITH, JOHN ... True False
Expected Output for Sample Data 2:
Record ID Record Name ... overlap? total records consec >=3?
0 1 SMITH, JOHN ... True False
1 2 SMITH, JOHN ... True False
2 3 SMITH, JOHN ... True False
3 4 SMITH, JOHN ... False False
4 5 SMITH, JOHN ... True False
This gives a false positive. Its just grouping by Name and Date and counting the number of overlaps. But doesn't look at if those overlaps are consecutive.