Calculate minimum of overlapping window
I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:
These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:
I am a bit lost here on what direction to take, does anyone have any suggestions?
python window overlap pooling
add a comment |
I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:
These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:
I am a bit lost here on what direction to take, does anyone have any suggestions?
python window overlap pooling
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11
add a comment |
I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:
These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:
I am a bit lost here on what direction to take, does anyone have any suggestions?
python window overlap pooling
I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:
These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:
I am a bit lost here on what direction to take, does anyone have any suggestions?
python window overlap pooling
python window overlap pooling
asked Nov 23 '18 at 9:35
Nienke MekkesNienke Mekkes
404
404
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11
add a comment |
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11
add a comment |
1 Answer
1
active
oldest
votes
Assuming that you are looking to define windows that do not overlap with the value of the minimum if the new window is the intersection of two old windows, we need to solve this issue by doing two things.
first we need to define the windows. i assume that if we get all the starting points and the end points we can do this as the windows don't have to be of equal size, just not overlapping each other.
my_list = np.sort(list(set(np.concatenate([df['Start'].values,df['End'].values]))))
then we build a new dataframe from this list:
new_df = pd.DataFrame({'Start':my_list[:-1],'End':my_list[1:]})
then we find the value of the min:
new_df['value'] = new_df.apply(lambda x: min(df[(df['Start'] <= x[0]) & (df['End'] >= x[1])]['Value']), axis = 1)
OUTPUT
Start End value
0 0 5 0.1
1 5 10 0.1
2 10 15 0.2
3 15 20 0.2
4 20 25 0.4
5 25 30 0.3
6 30 35 0.3
if you need a more detail explanation of what each line/function is doing, please feel free to ask for more details, i'll update the answer.
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443992%2fcalculate-minimum-of-overlapping-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that you are looking to define windows that do not overlap with the value of the minimum if the new window is the intersection of two old windows, we need to solve this issue by doing two things.
first we need to define the windows. i assume that if we get all the starting points and the end points we can do this as the windows don't have to be of equal size, just not overlapping each other.
my_list = np.sort(list(set(np.concatenate([df['Start'].values,df['End'].values]))))
then we build a new dataframe from this list:
new_df = pd.DataFrame({'Start':my_list[:-1],'End':my_list[1:]})
then we find the value of the min:
new_df['value'] = new_df.apply(lambda x: min(df[(df['Start'] <= x[0]) & (df['End'] >= x[1])]['Value']), axis = 1)
OUTPUT
Start End value
0 0 5 0.1
1 5 10 0.1
2 10 15 0.2
3 15 20 0.2
4 20 25 0.4
5 25 30 0.3
6 30 35 0.3
if you need a more detail explanation of what each line/function is doing, please feel free to ask for more details, i'll update the answer.
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
add a comment |
Assuming that you are looking to define windows that do not overlap with the value of the minimum if the new window is the intersection of two old windows, we need to solve this issue by doing two things.
first we need to define the windows. i assume that if we get all the starting points and the end points we can do this as the windows don't have to be of equal size, just not overlapping each other.
my_list = np.sort(list(set(np.concatenate([df['Start'].values,df['End'].values]))))
then we build a new dataframe from this list:
new_df = pd.DataFrame({'Start':my_list[:-1],'End':my_list[1:]})
then we find the value of the min:
new_df['value'] = new_df.apply(lambda x: min(df[(df['Start'] <= x[0]) & (df['End'] >= x[1])]['Value']), axis = 1)
OUTPUT
Start End value
0 0 5 0.1
1 5 10 0.1
2 10 15 0.2
3 15 20 0.2
4 20 25 0.4
5 25 30 0.3
6 30 35 0.3
if you need a more detail explanation of what each line/function is doing, please feel free to ask for more details, i'll update the answer.
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
add a comment |
Assuming that you are looking to define windows that do not overlap with the value of the minimum if the new window is the intersection of two old windows, we need to solve this issue by doing two things.
first we need to define the windows. i assume that if we get all the starting points and the end points we can do this as the windows don't have to be of equal size, just not overlapping each other.
my_list = np.sort(list(set(np.concatenate([df['Start'].values,df['End'].values]))))
then we build a new dataframe from this list:
new_df = pd.DataFrame({'Start':my_list[:-1],'End':my_list[1:]})
then we find the value of the min:
new_df['value'] = new_df.apply(lambda x: min(df[(df['Start'] <= x[0]) & (df['End'] >= x[1])]['Value']), axis = 1)
OUTPUT
Start End value
0 0 5 0.1
1 5 10 0.1
2 10 15 0.2
3 15 20 0.2
4 20 25 0.4
5 25 30 0.3
6 30 35 0.3
if you need a more detail explanation of what each line/function is doing, please feel free to ask for more details, i'll update the answer.
Assuming that you are looking to define windows that do not overlap with the value of the minimum if the new window is the intersection of two old windows, we need to solve this issue by doing two things.
first we need to define the windows. i assume that if we get all the starting points and the end points we can do this as the windows don't have to be of equal size, just not overlapping each other.
my_list = np.sort(list(set(np.concatenate([df['Start'].values,df['End'].values]))))
then we build a new dataframe from this list:
new_df = pd.DataFrame({'Start':my_list[:-1],'End':my_list[1:]})
then we find the value of the min:
new_df['value'] = new_df.apply(lambda x: min(df[(df['Start'] <= x[0]) & (df['End'] >= x[1])]['Value']), axis = 1)
OUTPUT
Start End value
0 0 5 0.1
1 5 10 0.1
2 10 15 0.2
3 15 20 0.2
4 20 25 0.4
5 25 30 0.3
6 30 35 0.3
if you need a more detail explanation of what each line/function is doing, please feel free to ask for more details, i'll update the answer.
edited Nov 23 '18 at 13:33
answered Nov 23 '18 at 10:13
AlexisAlexis
1,194414
1,194414
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
add a comment |
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
Thank you Alexis, this works very well and is fast.
– Nienke Mekkes
Nov 23 '18 at 12:34
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
@NienkeMekkes you're welcome. Always a pleasure to help. Don't forget to accept the answer to close the question if you are satisfied of this answer.
– Alexis
Nov 23 '18 at 13:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443992%2fcalculate-minimum-of-overlapping-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Minimum value when pooling the window? I do not understand your question.
– b-fg
Nov 23 '18 at 10:11