Skip to content

Instantly share code, notes, and snippets.

@travis23
Created September 24, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travis23/c6c01194e772c6d83835e31dd94b8f85 to your computer and use it in GitHub Desktop.
Save travis23/c6c01194e772c6d83835e31dd94b8f85 to your computer and use it in GitHub Desktop.
[Boundaries Between Range Boundaries] #endpoints #numpy #classify #pandas
def get_ranges_in_between_ranges(df, start_name, stop_name):
"""
Get range boundaries in between range boundaries arranged to be strictly increasing.
For example if we had three range boundaries where the range start and stop values
are found in two separate columns in a dataframe,
start, stop
-----------
0, 5
7, 8
12, 15
The range boundaries in between are
start, stop
-----------
5, 7
8, 12
"""
# This can be made into a one-liner if desired.
subset_df = df[[start_name, stop_name]]
v = subset_df.values
r = np.ravel(v)[1:-1]
rs = r.reshape(-1, 2)
return rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment