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
'C:\Users\Folder\\' + str(i) + '.txt'
or
'C:\Users\Folder\%s.txt' % i
or
'C:\Users\Folder\%s.txt'.format(i)
尝试以这种方式连接字符串:
location = 'C:\\Users\\Folder\\' + i + '.txt'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.