x_train_YS_1,y_train_YS_1 = x_train_YS.iloc[1:418+20*i,list(range(1,87))].values,y_train_YS.iloc[1:418+20*i,87].values提示我Too many indexers
时间: 2024-02-24 10:53:25 浏览: 61
这个错误提示表明你在对数据进行切片时使用了太多的索引器,可能是因为在 `iloc` 中同时使用了行索引和列索引。为了解决这个问题,可以分别使用行索引和列索引对数据进行切片。
你可以尝试修改代码如下:
```
start = 0
end = 418
cols = list(range(0)) + list(range(8, 95))
cols_1 = list(range(1, 87))
train_data = []
test_data = []
for i in range(14):
x_train_YS, y_train_YS = data.iloc[start:end, cols], data.iloc[start:end, 95]
x_test_YS, y_test_YS = data.iloc[start+418:end+438, cols], data.iloc[start+418:end+438, 95]
x_train_YS_1 = x_train_YS.iloc[1:end-1, cols_1].values
y_train_YS_1 = y_train_YS.iloc[1:end-1].values
x_test_YS_1 = x_test_YS.iloc[:, cols_1].values
y_test_YS_1 = y_test_YS.iloc[:, -1].values
train_data.append((x_train_YS_1, y_train_YS_1))
test_data.append((x_test_YS_1, y_test_YS_1))
start = end
end += 20 * (i + 2)
```
这样,我们对行和列的切片分别进行操作,避免了使用太多的索引器。
阅读全文