Created
September 24, 2019 15:42
-
-
Save travis23/c6c01194e772c6d83835e31dd94b8f85 to your computer and use it in GitHub Desktop.
[Boundaries Between Range Boundaries] #endpoints #numpy #classify #pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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