Home > other >  About pandas time overlap calculation
About pandas time overlap calculation

Time:05-26

Have the following df:
The order no. Start end
0 D0001 2021-01-01 08:12:23 2021-01-01 13:12:23
1 D0002 2021-02-13 18:12:23 2021-02-13 18:12:23
2 D0003 2021-02-11 10:12:23 2021-02-11 12:12:23
3 D0004 2021-01-01 09:12:23 2021-01-01 11:12:23
4 D0005 2021-01-04 08:12:23 2021-01-04 15:12:23
5 D0006 2021-01-05 08:12:23 2021-01-05 11:12:23
6 D0007 2021-01-03 08:12:23 2021-01-03 08:12:23
7 D0008 2021-01-01 09:12:23 2021-01-01 19:12:23
8 D0009 2021-01-01 11:12:23 2021-01-01 12:12:23
9 D0010 2021-01-02 09:12:23 2021-01-02 19:12:23
10 D0011 2021-01-02 11:12:23 2021-01-02 12:12:23

Used to record the vehicle taking orders for the time of shipment and arrival time,

Now require screening out if there is a time of the df overlapping records, if you have, and what a overlapping!

The implemented code is as follows:

 
S, e=df [[' start ', 'receiving end]]. To_numpy () T
# print (s, e)
M1=(s [: None] & gt; S) & amp; (s:, None] M2=(e [: None] Df [' overlap ']=(| m1 m2) any (1)
Df1=df [df [' overlap ']==True]


But can't locate which records and overlapping!
  • Related