Hi all experts,
I’m new to pytorch and I’ve got a KEY ERROR  issue below: Please help me solve it.
I have a created custom dataset class to access category columns for embedding and numerical columns separately, but I get key error when I try to iterate through elements of the data. Please see my code below:
class LoanDataset(Dataset):
def __init__(self, X, Y, emb_cols):
    X = X.copy()
    self.X1 = X.loc[:,emb_cols].copy().values.astype(np.int64) #categorical columns
    self.X2 = X.drop(columns=emb_cols).copy().values.astype(np.float32) #numerical columns
    self.y = Y
    
def __len__(self):
    return len(self.y)

def __getitem__(self, idx):
    return self.X1[idx], self.X2[idx], self.y[idx]

Next, I apply this to my x_train and x_test data like so:
train_ds = LoanDataset(x_train, y_train, emb_cols)
test_ds = LoanDataset(x_test, y_test, emb_cols)
batch_size = 64
traindl = DataLoader(x_train, batch_size=batch_size,shuffle=True)
testdl = DataLoader(x_test, batch_size=batch_size,shuffle=True)
I try to view elements of the train_ds with code below and get I key error:1
i = 1
for X1, X2, y in train_ds:
print(‘batch_num:’, i)
i = i+1
print(X1,X2,y)
So I tried to view train_ds[1] and I get key error  1 as well. PLEASE HELP. Would appreciate your support, Thanks