Key Error: None of [Int64Index...] dtype='int64] are in the columns

You created your scaled_inputs_all DataFrame using loc function, so it most likely contains no consecutive indices.

On the other hand, you created shuffled_indices as a shuffle from just a range of consecutive numbers.

Remember that scaled_inputs_all[shuffled_indices] gets rows of scaled_inputs_all which have index values equal to elements of shuffled_indices.

Maybe you should write:

scaled_inputs_all.iloc[shuffled_indices]

Note that iloc provides integer-location based indexing, regardless of index values, i.e. just what you need.


I had this problem too. I solved it by changing the data frame and series to array.

try the follwing codeline:

scaled_inputs_all.iloc[shuffled_indices].values 

might have someone also get the same error in working with KFOLD in machine learning.

And the solution for this is as below:

Click here to watch solutinon

You need to use iloc:

 X_train, X_test = X.iloc[train_index], X.iloc[test_index]

 y_train, y_test = y.iloc[train_index], y.iloc[test_index]