I have a directory of images, and I want to load all the paths to each image into a pandas column. However I am not sure how I can extract every path and put them into the column. Is there a built in function that will iterate over all of the images in the directory and put the paths from each one into a pandas column? Or would I use some sort of for loop? To specify, I need the actual paths, not the image names, as I am wanting to use the flow_from_dataframe tensorflow function as I have labels in a pandas dataframe. I am still quite new to this so help would be appreciated.
Asked
Active
Viewed 1,118 times
-2
-
1Does this answer your question? [How do I list all files of a directory?](https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory) – Laurent May 01 '22 at 14:23
1 Answers
0
Lets call the directory that contains the images source_dir. Then try
import os
import pandas as pd
filepaths=[]
filelist=os.listdir(source_dir)
for f in filelist:
fpath=os.path.join(source_dir,f)
filepaths.append(fpath)
Fseries=pd.Series(filepaths, name='filepaths')
dataframe=pd.concat([Fseries], axis=1)
print (df.head())

Gerry P
- 7,662
- 3
- 10
- 20