Match nearest coordinates in Python. Provide code please. house_no = ["House_1", "House_2"] house_coord = [(145.03552300

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Match nearest coordinates in Python. Provide code please. house_no = ["House_1", "House_2"] house_coord = [(145.03552300

Post by answerhappygod »

Match nearest coordinates in Python. Provide code
please.
Match Nearest Coordinates In Python Provide Code Please House No House 1 House 2 House Coord 145 03552300 1
Match Nearest Coordinates In Python Provide Code Please House No House 1 House 2 House Coord 145 03552300 1 (231.88 KiB) Viewed 14 times
house_no = ["House_1", "House_2"]
house_coord = [(145.03552300005, -37.80042), (145.158,
-37.81172)]
nearest_station = ["0", "0"]
distance = ["0", "0"]
data = {"House": house_no, "Longitude, Latitude":house_coord,
"station": nearest_station,
"distance": distance}
house = pd.DataFrame(data)
train_station_id = ["001", "002", "003", "004"]
lat_station = ["-37.820099201166606","-37.839106569914904",
"-37.821485232678235", "-37.884380634492565"]
long_station = ["145.1498012900773", "144.87597859808383",
"145.03651736595447", "144.9943229877339"]
data_station = {"Station_id": train_station, "Latitude":
lat_station,
"Longitude": long_station}
station = pd.DataFrame(data_station)
Python. Match nearest coordinates and distance 2 data frames are given, one about houses, and the other about train stations: import pandas as pd. house no ["House_1", "House_2"] train station_id = ["001", "002", "003", "004"] house_coord= [(145.03552300005, -37.80042), (145.158, -37.81172)] nearest station = ["0","0"] lat station ["-37.820099201166606","-37.839106569914904" "-37.821485232678235", "-37.884380634492565"] distance ["0","0"] long station = [145.1498012900773", "144.87597859808383", 145.03651736595447", "144.9943229877339"] data = {"House": house_no, "Longitude, Latitude": house_coord, "station": nearest station, data station = {"Station_id": train station, "latitude": lat station, "Longitude": long station) "distance": distance} pd.DataFrame (data) house house station = pd.DataFrame(data_station) station Station_id Latitude Longitude House Longitude, Latitude station distance 0 Station 1 -37.820099201166606 145.1498012900773 0 House 1 (145.03552300005, -37.80042) 0 0 1 Station 2 -37.839106569914904 144.87597859808383 1 House 2 (145.158, -37.81172) 0 0 2 Station 3 -37.821485232678235 145.03651736595447 3 Station 4 -37.884380634492565 144.9943229877339 ■ Station_id: Train station id ▪ House: house number ▪ Longitude, Latitude: Coordinates of corresponding house ▪ Latitude: Latitude of corresponding station ■ Station: Nearest train station (default is 0) ▪ Longitude: Longitude of corresponding station ▪ Distance: Nearest train station distance (default is 0) Task 1: Populate the station column in house data frame with the nearest Station_id. ■ For each house in the house data frame, use their coordinates to find the nearest train station using the coordinates from the station data frame. Task 2: Populate the distance column in house data frame with the calculated distance of the nearest train station as derived from Task 1. ▪ Distances are to be derived from their respective coordinates using the Haversine Distance. ▪ Distance output in kilometres, with 8 digits after the decimal Notes: o Any libraries within python are allowed o Pay attention to the data types in the data frames o Haversine Distance is to be used to calculate distance. The values in the sample output is only a sample - actual values may differ slightly. Sample Output: (Note that output values may not need to exactly match sample) House Longitude, Latitude station distance 0 House_1 (145.03552300005, -37.80042) 3 2.34502421 1 House 2 (145.158, -37.81172) 1 1.18530003
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply