我有四个数组:
per_1_start_time = [[Timestamp('2014 -01-20 13:06:00+ 0100',tz='pytz.FixedOffset(60)')] [Timestamp('2014 -02-04 10:31:00+ 0100',tz='pytz.FixedOffset(60)')]]
per_1_stop_time = [[Timestamp('2014 -01-20 13:10:11.372000+ 0100',tz='pytz.FixedOffset(60)')] [Timestamp('2014 -02-04 10:35:47.338000+ 0100',tz='pytz.FixedOffset(60)')]]
per_2_start_time = [[Timestamp('2014 -01-20 13:08:00+ 0100',tz='pytz.FixedOffset(60)')] [Timestamp('2014 -01-20 13:08:00+ 0100',tz='pytz.FixedOffset(60)')]]
per_2_stop_time = [[Timestamp('2014 -01-20 13:09:03.472000+ 0100',tz='pytz.FixedOffset(60)')] [Timestamp('2014 -01-20 13:09:03.472000+ 0100',tz='pytz.FixedOffset(60)')]]
我想找出person 1和person 2在一起的时间(如果有的话)
这就是我尝试的(抱歉这个可怕的语法,我对这个很陌生):
intersept_loc = []
if np.less(per_1_start_time,per_2_start_time).any()& np.greater(per_1_stop_time,per_2_start_time).any():
intersept_loc.append(np.subtract(per_1_stop_time,per_2_start_time))
elif np.greater(per_1_start_time,per_2_start_time).any()& np.greater(per_2_stop_time,per_1_start_time).any():intersept_loc.append(np.subtract(per_2_stop_time,per_1_start_time))elif np.less(per_1_start_time,per_2_start_time).any()& np.greater(per_1_stop_time,per_2_stop_time).any():intersept_loc.append(np.subtract(per_2_stop_time,per_2_start_time))elif np.greater(per_1_start_time,per_2_start_time).any()& np.less(per_1_stop_time,per_2_stop_time).any():intersept_loc.append(np.subtract(per_1_stop_time,per_1_start_time))else:intersept_loc.append(0)
print(intersept_loc3)
这就是我得到的:array([[Timedelta('0 days 00:02:11.372000')],[Timedelta('14 days 21:27:47.338000')]],dtype=object)]第一个时间增量是正确的,但它也在第二行执行功能,这是我不想要的。如果有人能给予我一些指导,我将不胜感激
1条答案
按热度按时间vfh0ocws1#
试试这个,我想会有用的。
字符串