f = import("F.csv"); g = import("G.csv"); for fr in f { for gr in g { if not empty(fr[1]) and not empty(fr[2]) and fr[1] == gr[0] and fr[2] == gr[1] { out.add(fr[0], gr[2]); } } }