我完成了大部分工作,但这是一个琐碎的问题,我不能解决这个问题。
所以,我有两个看起来像这样的TSV文件。
文件一
"Cars" 2
"Cars" 1
"Bikes" 21
文件二
"Bikes" 21 "Triumph"
"Cars" 2 "vauxhall.jpg"
我想将第二个文件与第一个文件关联起来,所以我最终会得到类似......
的内容"Cars" 2 "vauxhall.jpg"
"Bikes" 21 "Triumph"
我将如何在Python中执行此操作?我试过这个......
import csv
with open("../csvfiles/created/redandyellow.csv","rb") as rayf:
rayfs = csv.reader(rayf, delimiter='\t', lineterminator='\n')
with open("../csvfiles/photos.csv","rb") as phf:
phfs = csv.reader(phf, delimiter='\t', lineterminator='\n')
for phrow in phfs:
for rayrow in rayfs:
if phrow[1] == rayrow[1]:
print phrow[1] + ", " + phrow[1]
无济于事。