如下两个CSV文件gzb.csvid,lat,lng1,3,42,4,93,4,64,5,55,7,4gzb1.csvid,lat,lng,name1,3,4,A2,2,2,V3,3,3,C4,5,5,D5,4,9,Fgzb里的lat满足在gzb1(lat-1,lat+1)范围内,同时gzb的lng满...
如下两个CSV文件
gzb.csv
id,lat,lng
1,3,4
2,4,9
3,4,6
4,5,5
5,7,4
gzb1.csv
id,lat,lng,name
1,3,4,A
2,2,2,V
3,3,3,C
4,5,5,D
5,4,9,F
gzb里的lat满足在gzb1(lat-1,lat+1)范围内,同时gzb的lng满足在gzb1(lng-1,lng+1)范围内,就在gzb里记录gzb1的name
我写的代码。。得到一片空白。。。。。。。。。。
import csv
from itertools import islice
f1 = csv.reader(open('gzb.csv'))
f2 = csv.reader(open('gzb1.csv'))
writer = csv.writer(open('gzb2.csv', 'w'), delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["id", "lat", "lng", "sta"])
for line in islice(f1, 1, None):
line[1] = float(line[1])
line[2] = float(line[2])
a = line[1]
b = line[2]
for line1 in islice(f2, 1, None):
line1[1] = float(line1[1])
line1[2] = float(line1[2])
line1[3] = str(line1[3])
c = line1[1]
d = line1[2]
e = line1[3]
if a > c - 1 and a < c + 1 and b > d - 1 and b < d + 1:
writer.writerow([line[0:3] + [e]])
展开