As per my knowledge, you need to use boolean indexing
fraud_samples = dataset[dataset.Class == 1]
if you want to use indices
fraud_indices = fraud_samples.index
but I am getting an error:
positional indexers are out-of-bounds
I am getting this error because we have not specified the indices. I am using the sample dataset as shown below:
dataset = pd.DataFrame({'Class':[0,1,0,1]}, index=[0,1,3,5])
print (dataset)
Class
0 0
1 1
3 0
5 1
fraud_indices = np.array(dataset[dataset.Class == 1].index)
print (fraud_indices)
[1 5]
You cannot select the rows it thoughts you an error:
fraud_samples = dataset.iloc[fraud_indices,
print (fraud_samples)
Error:
IndexError: positional indexers are out-of-bounds
But you can select using the indices numbers:
fraud_samples = dataset.loc[fraud_indices,
print (fraud_samples)
Class
1 1
5 1
As shown above, you will get the proper output. If you are a beginner and want to know more about Data Science the do check out the Data Science course