I think this StackOverflow question illustrates both the premise and the problem quite well. In short, it would be nice to have something like df.window(df.somecolumn == 'ping', winsize=5) which would return a subset of df such that for each row where df.somecolumn=='ping', we select the 5 previous lines and five following lines.

This would be particularly useful for time-locking epochs to certain values (e.g. TTLs from some hardware).

Comment From: jreback

I answered your question. http://stackoverflow.com/questions/24650117/how-can-i-select-all-dataframe-rows-that-are-within-a-certain-distance-of-a-give/24653406#24653406.

I think this would be a nice addition to the cookbook. If you'd like to submit a pull-request would be great. Pls submit a template function signature (with a doc-string) for API consideration.

Comment From: louist87

@jreback Great, thank you very much for your answer and your encouragement! Expect a pull-request shortly!

Comment From: jreback

you can do this in a nice way by using offsets for the window.