Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Lengths of overlapping time ranges listed by rows

$
0
0

I am using pandas version 1.0.5

The example dataframe below lists time intervals, recorded over three days, and I seek where some time intervals overlap every day.

Interim- for illustration

For example,one of the overlapping time across all the three dates (yellow highlighted) is 1:16 - 2:13. The other (blue highlighted) would be 18:45 - 19:00

So my expected output would be like: [57,15] because

  • 57 - Minutes between 1:16 - 2:13.
  • 15 - Minutes between 18:45 - 19:00

Please use this generator of the input dataframe:

import pandas as pddat1 = [    ['2023-12-27','2023-12-27 00:00:00','2023-12-27 02:14:00'],    ['2023-12-27','2023-12-27 03:16:00','2023-12-27 04:19:00'],    ['2023-12-27','2023-12-27 18:11:00','2023-12-27 20:13:00'],    ['2023-12-28','2023-12-28 01:16:00','2023-12-28 02:14:00'],    ['2023-12-28','2023-12-28 02:16:00','2023-12-28 02:28:00'],    ['2023-12-28','2023-12-28 02:30:00','2023-12-28 02:56:00'],    ['2023-12-28','2023-12-28 18:45:00','2023-12-28 19:00:00'],    ['2023-12-29','2023-12-29 01:16:00','2023-12-29 02:13:00'],    ['2023-12-29','2023-12-29 04:16:00','2023-12-29 05:09:00'],    ['2023-12-29','2023-12-29 05:11:00','2023-12-29 05:14:00'],    ['2023-12-29','2023-12-29 18:00:00','2023-12-29 19:00:00']       ]df = pd.DataFrame(dat1,columns = ['date','Start_tmp','End_tmp'])df["Start_tmp"] = pd.to_datetime(df["Start_tmp"])df["End_tmp"] = pd.to_datetime(df["End_tmp"])

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>