【发布时间】:2014-12-18 23:33:15
【问题描述】:
我对 python3 很陌生,我确信我的问题非常基本。 我一直在网上寻求帮助,我得到的最接近的来自线程 Find Common Region in two CSV File in PYTHON
但是,就我而言,它似乎并没有遍历每一行并停在第一行。 所以在我的第一个 csv 中,我有 2 行,可以说:
A,1,A1
B,2,B2
现在在我的第二个 csv 中,我有一千行,类似于
A,1,B5
A,2,A2
B,2,C6
B,3,C7
C,3,D7
C,4,D8
......
我的代码如下:
read1 = csv.reader(csv1)
for row1 in read1:
read2 = csv.reader(csv2)
for row2 in read2:
if row1[0] == row2[0] and row1[1] == row2[1]:
print('There is a match', row1[0], row1[1])
但是,我的输出是 有一个匹配 A 1 它只找到第一个匹配项而不找到另一个匹配项:B 2 我不确定我的迭代出了什么问题:
提前感谢您的帮助
【问题讨论】:
标签: python csv python-3.x iteration