##### How to get indices of minimum time difference
 How to get indices of minimum time difference Mekala Not Blown Up Yet Posts: 67 Threads: 40 Joined: May 2020 Reputation: Nov-09-2020, 03:06 PM Hi, I have below data: df1: time1 time2 2020/11/05 20:30:23 2020/11/05 20:20:23 2020/11/05 20:40:12 2020/11/05 20:20:23 2020/11/05 20:49:53 2020/11/05 20:20:23 2020/11/05 20:56:28 2020/11/05 20:20:23 df2: time 2020/11/05 20:36:23 I want to get df1 row indices (1) time2 > time, 2. time1 should be close (minimum difference). How to get this. I can only filter df1_filter = df1[df1['time1'] < df2['time'], but after this I sruck how to get match the (1) time2 > time, 2. time1 should be close (minimum difference). Please kindly someone help, Reply Posts: 4,983 Threads: 16 Joined: Feb 2020 Reputation: Nov-10-2020, 11:09 PM (This post was last modified: Nov-10-2020, 11:09 PM by deanhystad.) The first thing you need to do is extract the datetime strings from the lines. Can you do that? To determine the shortest duration between the two times you need to convert them to something you can subtract. Any units will do, hours, days, seconds, as long as both times are converted to the same time unit. Even a datetime object will work. Can you do this? The last part is the easiest. Calculate the duration for each line and keep track of the shortest duration. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Sum up Time difference tester_V 10 677 Apr-06-2023, 06:54 AM Last Post: Gribouillis "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 653 Feb-11-2023, 07:03 PM Last Post: deanhystad How to get index of minimum element between 3 & 8 in list Mekala 2 2,001 Nov-10-2020, 12:56 PM Last Post: DeaD_EyE How to calculate time difference between each row of dataframe in seconds Mekala 1 1,966 Jul-16-2020, 12:57 PM Last Post: Larz60+ Finding MINIMUM number in a random list is not working Mona 5 2,338 Nov-18-2019, 07:27 PM Last Post: ThomasL Delete minimum occurence in a string RavCOder 10 2,972 Nov-12-2019, 01:08 PM Last Post: RavCOder Minimum size Amniote 8 2,939 Jul-10-2019, 02:58 PM Last Post: nilamo Correlation of Incidents using time difference Rajhesh 1 1,416 Jun-27-2019, 03:44 PM Last Post: Larz60+ Armstrong in minimum lines Gaurav 1 1,703 Sep-03-2018, 03:46 PM Last Post: j.crater Watson Personality Insight: minimum number of words kiton 0 2,362 Apr-28-2018, 03:28 PM Last Post: kiton

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020