Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import math
- csv2 = open('Merge.csv','w')
- with open("stationLongLatVind.csv") as f:
- read1 = csv.reader(f, delimiter=';')
- weather= filter(None,read1)
- print "klar"
- with open("GPSCoord.csv") as f:
- read2 = csv.reader(f, delimiter=';')
- train= filter(None,read2)
- print "klar"
- def distance(p0, p1):
- return math.sqrt((float(p0[0]) - float(p1[0]))**2 + (float(p0[1]) - float(p1[1]))**2)
- csv2.write("Train station;")
- csv2.write("Weather station id;")
- csv2.write("Distance;")
- csv2.write("tlong;")
- csv2.write("tlat;")
- csv2.write("wlong;")
- csv2.write("wlat")
- csv2.write("\n")
- for index1 in range(len(train)-1):
- shortest = 999
- row=[]
- for index2 in range(len(weather)-1):
- if distance(train[index1+1][0:2], weather[index2+1][2:4]) < shortest and weather[index2+1][1].startswith("2014"):
- shortest = distance(train[index1+1][0:2], weather[index2+1][1:3])
- a = train[index1+1][0]
- b = train[index1+1][1]
- c = train[index1+1][2]
- d = weather[index2+1][0]
- e = weather[index2+1][2]
- f = weather[index2+1][3]
- csv2.write(c+";")
- csv2.write(d+";")
- csv2.write(str(shortest)+";")
- csv2.write(a+";")
- csv2.write(b+";")
- csv2.write(e+";")
- csv2.write(f)
- csv2.write("\n")
- print index1
- csv2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement