I would need to read a file from a list. Specifically, I would need to look for a file stored in a specific directory. Since it may happen to not remember all the files stored there or just the right name, I would need to list theirs. To do this step, I found this useful post:
How do I display the the index of a list element in Python?
Now I have a list like the following:
file=[]
for f in glob.glob("*.txt"):
file.append(f)
for (num,item) in enumerate(file):
print(num+1,item) # updated after Thierry's comment
Output:
1 file 1.txt
2 file_2.txt
3 file_3.txt
...
I would like to read the file using
query=input("Please add your selection: ") # just the number
if int(query) in enumerate(datasets):
dataset=pd.read_csv('path_name'+1) # I would need to add the path to the file and, by the number, the filename
df = pd.DataFrame(dataset)
it gives me the error: TypeError: 'module' object is not iterable.
How could I do this?