遍历一个文本文件和一个 Excel 文件
Looping though a text file and an Excel file
我想查看文件中的一行是否包含(不等于)Excel 文件中的一列。
data = pd.read_excel('C:/Users.../excel.xlsx', sep='\t')
f=open("list.txt", "r+")
for line in f:
line = line.rstrip()
for vh in data["Column_of_interest"]:
vh = vh.rstrip()
match = line in vh
print (match)
break
结果应该是全部 'True' 但它只给了我 'True' 第一个。
即使找不到匹配项,您也会崩溃...您发布的代码将文本文件中的所有行与 Excel 文件的第一行进行比较,因为它总是执行"break" 在内部 for.
的第一次迭代结束时
data = pd.read_excel('C:/Users.../excel.xlsx', sep='\t')
f=open("list.txt", "r+")
for line in f:
line = line.rstrip()
for vh in data["Column_of_interest"]:
vh = vh.rstrip()
if line in vh:
print True
continue
我想查看文件中的一行是否包含(不等于)Excel 文件中的一列。
data = pd.read_excel('C:/Users.../excel.xlsx', sep='\t')
f=open("list.txt", "r+")
for line in f:
line = line.rstrip()
for vh in data["Column_of_interest"]:
vh = vh.rstrip()
match = line in vh
print (match)
break
结果应该是全部 'True' 但它只给了我 'True' 第一个。
即使找不到匹配项,您也会崩溃...您发布的代码将文本文件中的所有行与 Excel 文件的第一行进行比较,因为它总是执行"break" 在内部 for.
的第一次迭代结束时data = pd.read_excel('C:/Users.../excel.xlsx', sep='\t')
f=open("list.txt", "r+")
for line in f:
line = line.rstrip()
for vh in data["Column_of_interest"]:
vh = vh.rstrip()
if line in vh:
print True
continue