我需要从一个csv文件中提取一列,并将此列与另一个csv文件中的另一列进行比较以找到匹配项。
我无法使用Panda,我提取了表格并将其卡住。
def first():
with open('1.csv') as csv_file:
for line in csv_file.readlines():
array = line.split(',')
list_pk = array[1]
def sec():
with open('2.csv') as csv_file:
for line in csv_file.readlines():
array = line.split(',')
list_fk = array[0]
答案 0 :(得分:0)
我希望它将对您有帮助
def findMatch():
with open('old.csv', 'r', newline='') as t1, open('new.csv', 'r', newline='') as t2:
for line1,line2 in zip(t1,t2):
if line1.split(' ')[colum_index]!=line2.split(' ')[colum_index]:
print(line1,line2)
findMatch()
使用zip_longest
from itertools import zip_longest
def findMatch():
with open('old.csv', 'r', newline='') as t1, open('new.csv', 'r', newline='') as t2:
for line in zip_longest(t1,t2):
print(line)
if line[0]!=line[1]:
print("nq")
findMatch()
zip_最长引用:-zip_longest