In my code below I am trying to randomly parse a dataframe. Then based on the random number generated I want to delete/drop that row and but it into another dataframe. Later I want then do a comparison between the plucked row and the entire dataframe entries left. However, I cannot seem to remove the randomly generated index row from my dataframe. Whenever I run my print statement after it still appears. Any idea what I am doing wrong?
I have tried data.drop(data.index[y]) but this does not drop an rows as my dataframe when printed at the end shows all of the rows and looks like nothing was dropped.
col_names = ['letter','m00', 'mu02', 'mu11', 'mu20', 'mu03', 'mu12', 'mu21', 'mu30']
data.head()
data = pd.read_csv('traindat.txt', delim_whitespace = True,skiprows = 1, header = None)
plucked_df = pd.DataFrame(columns = col_names)
data.columns = col_names
#df.loc[row,column] or df.loc[0,'mu00']
#print(data.loc[3,'m00'])
print(data)
x = len(data)
#df_marks = df_marks.append(new_row, ignore_index=True)
for i in range(0,x):
y = random.randint(0,x)
#print(y)
print(data.loc[y])
plucked_df = plucked_df.append(data.loc[y],ignore_index =True)
#print(plucked_df)
#data.drop([y])
data.drop(data.index[y])
print(data.index[y])
#del data[y]
data.reset_index(drop=True,inplace = True)
x = len(data) -1
#print(data)
#print(len(data))
print("data",data)
print("pluck",plucked_df)