简体   繁体   English

滚动窗口,熊猫窗口大小重叠50%

[英]rolling window with 50% overlapping on window size in pandas

I have a data frame like this which is imported from a CSV. 我有一个这样的数据框,它是从CSV导入的。 Data frame 数据框

I would like to create a sliding window of size 256 with overlapping of 50%. 我想创建一个大小为256且重叠率为50%的滑动窗口。 For example, window1 should contain data from index 0-255, window2 should contain data from index 128-383 and so on until all the data is split in their respective windows. 例如,window1应该包含索引0-255的数据,window2应该包含索引128-383的数据,依此类推,直到所有数据在各自的窗口中拆分为止。 I am trying rolling.windows from pandas to create windows without any success. 我正在尝试从pandas滚动roll.windows创建窗口,但没有成功。 I want to achieve something like this. 我想实现这样的目标。 Overlapping windows How can I do that using the optimized methods included in Pandas or Numpy? 重叠窗口如何使用Pandas或Numpy中包含的优化方法来做到这一点?

def windows(d, w, t):  
    r = np.arange(len(d))   
    s = r[::t]   
    z = list(zip(s, s + w))   
    f = '{0[0]}:{0[1]}'.format
    g = lambda t: d.iloc[t[0]:t[1]]   
    return pd.concat(map(g, z), keys=map(f, z))   

windows(d,256,128) 窗口(d,256128)
d: dataframe w: window size(256) t: overlapping factor (eg. 50% of window size ie 128). d:数据帧w:窗口大小(256)t:重叠因子(例如,窗口大小的50%,即128)。
so after passing the above-mentioned parameters, the function returns a new dataframe with the window size of 256 with 50% overlapping. 因此,在传递了上述参数后,该函数将返回窗口大小为256,重叠率为50%的新数据帧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM