I'm getting this IndexError: single positional indexer is out-of-bounds for the below code
I'm getting this IndexError: single positional indexer is out-of-bounds for the below code
数据集有 50 行和 75 列。
我收到此单个位置索引器越界错误。
谁能帮我解决这个问题?
def load_real_samples():
# load cifar10 dataset
#(trainX, _), (_, _) = load_data()
dataset = []
#print(trainX.shape)
paths = pd.read_csv(r"C:\Users\Vaishnav\Documents\MiniProject\data_Mild.csv")
paths.head(5)
for i in range(1,50):
if(os.path.exists(paths.iloc[i][i])):
im = Image.open(paths.iloc[i][i])
resized_im = im.resize((round(im.size[0]*0.0625), round(im.size[1]*0.0625)))
image=asarray(resized_im)
data = asarray(image)
dataset.append(data)
trainX=np.array(dataset)
#y_train=np.array([0,0,0,0])
print(trainX.shape)
X = trainX.astype('float32')
X = (X - 127.5) / 127.5
return X
dataset = load_real_samples()
错误:
paths.head(5)
9 for i in range(1,50):
---> 10 if(os.path.exists(paths.iloc[i][i])):
11 im = Image.open(paths.iloc[i][i])
12 resized_im = im.resize((round(im.size[0]*0.0625), round(im.size[1]*0.0625)))
IndexError: single positional indexer is out-of-bounds
Index out-of-bounds 表示路径数据框中的索引少于 50 个。
此外,当您使用 iloc[i][i] 时,这意味着您在 first_row 中访问 i-row 和 i-element,如果它不是单元格中的列表而是字符串,您将得到一个关键错误。尝试以下操作:
for i in range(1, paths.shape[0]):
if(os.path.exists(paths.iloc[i].values[0])):
im = Image.open(paths.iloc[i].values[0])
或者尝试使用避免使用 range() 的路径访问您的列:
for path in paths.your_column_with_path_strings:
if(os.path.exists(path)):
im = Image.open(path)
数据集有 50 行和 75 列。 我收到此单个位置索引器越界错误。 谁能帮我解决这个问题?
def load_real_samples():
# load cifar10 dataset
#(trainX, _), (_, _) = load_data()
dataset = []
#print(trainX.shape)
paths = pd.read_csv(r"C:\Users\Vaishnav\Documents\MiniProject\data_Mild.csv")
paths.head(5)
for i in range(1,50):
if(os.path.exists(paths.iloc[i][i])):
im = Image.open(paths.iloc[i][i])
resized_im = im.resize((round(im.size[0]*0.0625), round(im.size[1]*0.0625)))
image=asarray(resized_im)
data = asarray(image)
dataset.append(data)
trainX=np.array(dataset)
#y_train=np.array([0,0,0,0])
print(trainX.shape)
X = trainX.astype('float32')
X = (X - 127.5) / 127.5
return X
dataset = load_real_samples()
错误:
paths.head(5)
9 for i in range(1,50):
---> 10 if(os.path.exists(paths.iloc[i][i])):
11 im = Image.open(paths.iloc[i][i])
12 resized_im = im.resize((round(im.size[0]*0.0625), round(im.size[1]*0.0625)))
IndexError: single positional indexer is out-of-bounds
Index out-of-bounds 表示路径数据框中的索引少于 50 个。 此外,当您使用 iloc[i][i] 时,这意味着您在 first_row 中访问 i-row 和 i-element,如果它不是单元格中的列表而是字符串,您将得到一个关键错误。尝试以下操作:
for i in range(1, paths.shape[0]):
if(os.path.exists(paths.iloc[i].values[0])):
im = Image.open(paths.iloc[i].values[0])
或者尝试使用避免使用 range() 的路径访问您的列:
for path in paths.your_column_with_path_strings:
if(os.path.exists(path)):
im = Image.open(path)