-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdistance_matrix.py
36 lines (30 loc) · 1.07 KB
/
distance_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import googlemaps
import csv
import pandas as pd
list0 = []
list1 = []
list2 = []
list3 = []
with open("Output1.csv", "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for lines in csv_reader:
if lines[0] != 'City 1':
list0.append(lines[0])
with open("Output1.csv", "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for lines in csv_reader:
if lines[1] != 'City 2':
list1.append(lines[1])
with open("Output1.csv", "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for lines in csv_reader:
if lines[2] != 'Graph':
list2.append(lines[2])
for i, j in zip(list0, list1):
gmaps = googlemaps.Client(key='AIzaSyB1OUZUeW1mWl6kIssk2yLM8e3Rqb0ON1s')
result = gmaps.directions(i, j, mode = "driving", avoid = None, departure_time = None)
result1 = (result[0]['legs'][0]['distance']['text'])
list3.append(result1)
data = dict(City1=list0, City2=list1, Graph=list2, Google=list3)
df = pd.DataFrame(data)
df.to_csv(r'Final.csv', sep=',', index=False)