'Problem iterating over images in Python 3
I am trying to iterate over some images, and call a method on them. The actual method is irrelevant to my problem, so I have tried to put a minimal example of my issue below :
df = pd.read_csv('csv_file.csv')
for index, row in df.iterrows():
--> with open('ImagesFolder\\' + df.LocalImage, 'rb') as images_file:
callMethod()
Error on the "with" line (see arrow).
TypeError: expected str, bytes or os.PathLike object, not Series
It should be opening a local image, with the name gotten from the CSV file, and calling the method. Instead the "with" is causing the above issue.
Solution 1:[1]
Agree with @DeepSpace.
You could also transform Series to String by
df.LocalImage.to_string(index=False)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lsv |
