如何通过无循环的简单操作获取数据?

时间:2018-10-10 11:01:29

标签: python pandas

我有一个类似的数据:

      col1 col2 col3
1     1    0.1  0.4
2     1.4  0.6  9.4
...
2000  2.1  0.1  2.3

data.shape=(2000,3)。使用循环方法设置moving_window=20seq_len=100seq_interval=10,以生成训练样本:

start = 0
sample_counts = (data.shape[0]-moving_window)/moving_window
samples = []
for i in range(sample_counts):
    start += moving_window*i
    end = start + seq_len*seq_interval
    samples.append(data.iloc[start:end].values)

此方法效率低。我想找到一种更有效的方法,例如reshape(不适用于这种情况)或其他整个操作。

0 个答案:

没有答案