def intersect(a, b):
    """Intersection of two intervals."""
intersection = max(a[0], b[0]), min(a[1], b[1])
if intersection[0] > intersection[1]:
    return None
return intersection

def interval_df_intersection(df1, df2):
    """Calculate the intersection of two sets of intervals stored in DataFrames.
    The intervals are defined by the "Start" and "End" columns.
    The data in the rest of the columns of df1 is included with the resulting
    intervals."""
tree = IntervalTree.from_tuples(zip(df1.Start.values, df1.End.values, df1.
    drop(['Start', 'End'], axis=1).values.tolist()))
intersections = []
for row in df2.itertuples():
    i1 = Interval(row.Start, row.End)
intersections += [(list(intersect(i1, i2)) + i2.data) for i2 in tree[i1]]
data_cols = list(df1.columns)
data_cols.remove('Start')
data_cols.remove('End')
return pd.DataFrame(intersections, columns=['Start', 'End'] + data_cols)
interval_df_intersection(mydataframe2, mydataframe1)
intersection of two columns of pandas dataframe