Imagine that I have two periods, which would be dates, but are integers here for simplicity:
ID START END VALUE
A 3 5 2
B 1 7 1
How do I get the intersection of the two start and end periods and the out-of-intersection parts of those two periods, returning something like this:
{ 'inner': [3, 5],
'outer': [[1, 2], [6, 7]] }
The first idea I had was to decompose this down to running along the set of all date possibilities and showing which parts are in and out by simply marking them on every date. That, however, will take an astonishingly long time.
The second approach I thought of was to generate list of every single date inside both ranges and run a check for which stamps match, and then somehow reduce it back into a period range... but that too seems exceedingly inefficient.
Is there some way to do this inside the standard libraries? Or the pandas libraries?