Skip to content

Instantly share code, notes, and snippets.

Created Sep 11, 2020
What would you like to do?
def graph_approach(df, start='start', end='end'):
start = df[start].values
end = df[end].values
graph = (start <= end[:, None]) & (end >= start[:, None])
n_components, indices = connected_components(graph, directed=False)
return df.groupby(indices).aggregate({'start': 'min','end': 'max'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment