Panda Excel File Reading
I am attempting to try and access an excel files rows and columns and do some basic distance calculations, but I keep getting the same values> i am attempting to find the distance from any two points of the map by iterating through the list of edges and their corresponding values in the dictionary I created. not sure what I am doing wrong here. Any guidance is appreciated.
import pandas as pd
import array
import numpy as np
import pyomo.environ as pyo
from math import sin, cos, sqrt, atan2, radians
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
distance = pd.read_csv("Distance File.csv")
distance.head()
d_long = distance["Longitude"]
d_lat = distance["Latitude"]
print(d_long)
print(d_lat)
distance_dict = {}
location = list(range(0, 10))
print(location)
for i in d_long:
for j in d_lat:
for x in location:
distance_dict[x] = i, j
# distance_dict.update(d1)
print(distance_dict)
opt = pyo.SolverFactory("glpk")
V = list(distance_dict.keys()) # List of Customers
Customers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
distance_dict = distance_dict # Dict of customers
E = []
for i in V:
for j in V:
if i != j:
E.append((i, j))
print(E)
c = {}
for (i, j) in E:
lat = radians(abs(distance_dict[i][1]))
lon = radians(abs(distance_dict[i][0]))
lat2 = radians(abs(distance_dict[j][1]))
lon2 = radians(abs(distance_dict[j][0]))
dlon = lon2 - lon
dlat = lat2 - lat
a = sin(dlat / 2) ** 2 + cos(lat) * cos(lat) * sin(dlon / 2) ** 2
c[i, j] = 2 * atan2(sqrt(a), sqrt(1 - a))
print(dlat)
print(c)