Key Error: None Of [int64index...] Dtype='int64] Are In The Columns
Solution 1:
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.
Solution 2:
might have someone also get the same error in working with KFOLD in machine learning.
And the solution for this is as below:
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]
Solution 3:
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
Solution 4:
If you reset your index after dropping rows from your dataframe, this should stop the key error.
You can do this by running this after you run df.drop
:
df = df.reset_index(drop=True)
Or, equivalently:
df.reset_index(drop=True, inplace=True)
Solution 5:
Got the same error:
KeyError:"None of [Int64Index([26], dtype='int64')] are in the [index]"
Solved by Saving the dataframe to a local file and open it,
like below:
df.to_csv('Step1.csv',index=False)
df = pd.read_csv('Step1.csv')
Post a Comment for "Key Error: None Of [int64index...] Dtype='int64] Are In The Columns"