I have a data frame consisting of 4 columns and 30000 rows. The last column is my target. I needed to exclude a sublist from that based on indices, and make a new dataset. To shed more light on it, I needed to exclude from the main dataset, 100 indices before and 100 indices after the index. I tried to define a function to do that through a for loop like below:
import pandas as pd
from sklearn.datasets import make_classification
df = make_classification(n_samples=10000, n_features=4)
NEW_middle_index = [1037, 1112, 1187, 1262, 1337, 1412, 1562]
XX , yy = [],[]
def data_reader(df,NEW_middle_index):
for i in NEW_middle_index:
y = df.iloc[i-100:i+100:,3]
X = df.iloc[i-100:i+100,:].drop(columns='Target')
XX.append(X)
yy.append(y)
return XX,yy
data_reader(df,NEW_middle_index) #edited here
It could do it for XX correctly but for yy, it is not capable of excluding and it repeats the same number of the first group which is incorrect. Also, I used a dictionary to do that, and again I got the same answer.