数据窗口重叠的滑动窗口分割

时间:2019-09-26 10:37:04

标签: python python-3.x dataframe machine-learning data-science

我正在research paper上工作,我发现有一个窗口重叠的窗口滑动分段

enter image description here

我的数据帧如下,

    Time  Temperature  BPM  GSR
0    0.5         31.0   70  223
1    1.0         32.0   69  225
2    1.5         31.5   68  230
3    2.0         32.5   67  240
4    2.5         33.0   68  244
5    3.0         34.0   69  250
6    3.5         33.5   68  251
7    4.0         30.0   69  255
8    4.5         30.6   70  252
9    5.0         31.5   71  260
10   5.5         31.0   72  240
11   6.0         32.0   71  250
12   6.5         33.0   70  260

代码如下:

from itertools import islice

def window(seq, n=2):
    "Returns a sliding window (of width n) over data from the iterable"
    "   s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ...                   "
    it = iter(seq)
    result = tuple(islice(it, n))
    if len(result) == n:
        yield result
    for elem in it:
        result = result[1:] + (elem,)
        yield result

但是问题在于上面的功能为1d列表提供了窗口滑动功能,并且没有任何重叠功能

Here是我的预期输出。

0 个答案:

没有答案