Reputation: 5552
I have several .txt files that I need to import to work in pandas, given a specific condition. Right now I do the same procedure for each one. I want to do it using a for-loop.This is what I have tried:
Each key is asociated with a different .txt file
All files are in same folder
filenames = ['a', 'b', 'c', 'd', 'e']
for i in filenames:
if name == i:
location = r'C:\Users\Folder\ + 'i'.txt'
What is the correct syntax to write that location path so that it can be used in a loop?
Thanks
Upvotes: 1
Views: 83
Reputation: 36
'C:\Users\Folder\\' + str(i) + '.txt'
or
'C:\Users\Folder\%s.txt' % i
or
'C:\Users\Folder\%s.txt'.format(i)
Upvotes: 2
Reputation: 32095
Try to concatenate the strings this way:
location = 'C:\\Users\\Folder\\' + i + '.txt'
Upvotes: 1