基于重叠的滑动窗口数据帧分割

2024-04-25 04:38:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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是我期望的输出。你知道吗


Tags: 数据from功能itresultwindowseqpaper