I\'m trying to shuffle my indices using the np.random.shuffle() method, but I keep getting an error that I don\'t understand. I\'d appreciate it if someone could help me puz
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.
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')
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
This below error occured while deleting the row with index based on the column value condition:
return self._engine.get_loc(key) File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 992, in pandas._libs.hashtable.Int64HashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item KeyError: 226
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
To resolve this make a list of index and delete the rows at once as below:
df.drop(index=list1,labels=None, axis=0, inplace=True,columns=None, level=None, errors='raise')
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]