I'm currently reading some images in from Google Drive in Google Colab and need to check that each image filename corresponds with a value in a pandas dataframe.
My code looks this this right now:
for img in os.listdir(path):
if img in df['column']:
add image to a folder
else:
add image to other folder
It seems that Python is checking to see if the actual image is in the dataframe, as opposed to the image name and adds all the images to the other folder. How can I make sure that I'm actually looking at the image file name when comparing with the dataframe? Thank you!
CodePudding user response:
_ in df[]
checks against the index, not value.
Try:
if img in df.values