I want to remove all rows of the dataframe that don't have the image names in the list in python. here is an example of the output with the following dataframe and list:
Dataframe:
ImageName | A
0001.jpg | 1
0002.jpg | 1
0003.jpg | 1
0004.jpg | 1
List:
'0003.jpg'
'0001.jpg'
Output dataframe:
ImageName | A
0001.jpg | 1
0003.jpg | 1
This is the code I made:
df = pd.read_csv("./imagenames.csv")
for index, row in df.iterrows():
a1=df.iloc[index][0]
a2=train_gen_labels
result=pd.Series(a1).isin(a2).any()
if(result==False):
df=df.drop(index)
else : positive=positive+1
However, this code returns the error: single positional indexer is out-of-bounds