#Using the 4 color theorem to locate neighbors is the best way to go
neighbors = pd.DataFrame(data = pd.read_csv('/content/drive/My Drive/Network resources/states and borders.csv'))
counties = pd.DataFrame(data = pd.read_csv('/content/drive/My Drive/Network resources/covid_county.csv'))
Airports = pd.DataFrame(data = pd.read_csv('/content/drive/My Drive/Network resources/Airport_data.csv'))
map = nx.Graph()
for i in range(0,50):
for j in range(0,10):
if pd.isnull(neighbors.iloc[i,j]) == False :
map.add_edge(neighbors.iloc[i,1], neighbors.iloc[i,j])
map.add_node('AK')#I've had to add Alaska manually
probdata = pd.DataFrame(columns = ['County', 'Airport', 'Infected', 'population','probability of infection', 'probability of choosing airport'])
state = 'ME'
count, ham = 0,0
tempdistances = {}
for i in range(0,3147):
tempdf = pd.DataFrame(columns = ['airport','distance'])
for j in range(0,519):
if counties.iloc[i,2] == state and map.has_edge(counties.iloc[i,2], Airports.iloc[j,1]) == True:
temp = Airports.iloc[j,4].replace(" ","%20")
temp1 = counties.iloc[i,1].replace(" ","%20")
driver.get('https://distancecalculator.globefeed.com/US_Distance_Result.asp?vr=apes&fromplace={},%20{},USA&toplace={},%20{},USA'.format(temp1, counties.iloc[i,2],temp, Airports.iloc[j,0]))
print('done')
time.sleep(10)
try:
drv = driver.find_element_by_id('drvDistance')
drv = drv.text
drv.replace("m","").replace("i","")
drv = float(drv)
tempdf.append({'airport':Airports.iloc[j,4],'distance':drv}, ignore_index = True)
driver.close()
except ValueError:
count = count + 1
driver.close()
tempdf.sort_values(by='distance', ascending=False)
..........
I feel that there is an error in closing the driver somewhere, but I am having trouble finding it. Any help would be appreciated.
I have added the driver.close()
functions under try and except, but it still does not seem to work for some reason.