我创建了一个集合,它有一些特定的名称。但是,这些名称是我必须使用Pandas包读取的文本文件。
例如,我可以说我的集合是这样的:
{0:"BDS00001",1:"BDS00002",2:"BDS00003",3:"BDS00013",4:"BDS00014",5:"BDS00015"…487:"BDS01952",488:"BDS01953"}
我可以使用循环,读取字典,转换BDS00001在BDS00001.txt,然后读取BDS00001.txt使用熊猫?
试试这个
all_files = { 0: 'BDS00001', 1: 'BDS00002'}
for k,v in all_files.items():
all_files[k]=v+'.txt'
print(all_files) # {0: 'BDS00001.txt', 1: 'BDS00002.txt'}
#________________________READING FILE________________________#
for a in all_files:
with open(a) as data:
print(data.read())