Calculate minimum of overlapping window












0















I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:



enter image description here



These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:



enter image description here



I am a bit lost here on what direction to take, does anyone have any suggestions?










share|improve this question























  • Minimum value when pooling the window? I do not understand your question.

    – b-fg
    Nov 23 '18 at 10:11
















0















I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:



enter image description here



These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:



enter image description here



I am a bit lost here on what direction to take, does anyone have any suggestions?










share|improve this question























  • Minimum value when pooling the window? I do not understand your question.

    – b-fg
    Nov 23 '18 at 10:11














0












0








0








I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:



enter image description here



These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:



enter image description here



I am a bit lost here on what direction to take, does anyone have any suggestions?










share|improve this question














I am having trouble with thinking of a way to solve a problem. I have a dataframe like the one below:



enter image description here



These are values for overlapping windows. My challenge is to calculate the minimum value when pooling(?) the windows. It should look like:



enter image description here



I am a bit lost here on what direction to take, does anyone have any suggestions?







python window overlap pooling






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this 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












Your Answer






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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this 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
















1














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.






share|improve this 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














1












1








1







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.






share|improve this 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.







share|improve this answer














share|improve this answer



share|improve this 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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy