Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python programming task - For the below df, create a new column called distance

ID: 3755142 • Letter: P

Question

Python programming task - For the below df, create a new column called distance with the calculated value of a distance between destination and origin.

Use Pandas dataframe in python code to find the distance between origin and destination's latitude and longitude value.

dest_lat dest_long origin_lat origin_long -30.429638 145.368873 -37.941974 143.252437 -31.684601 145.458705 -37.890761 143.990794 -30.609616 145.400781 -37.429572 145.088097 -37.284850 146.691658 -37.909647 145.595675 -37.548433 145.015170 -38.713994 143.053960 -37.066194 146.193824 -38.836916 144.572966

Explanation / Answer

import pandas as panda

import math

data = panda.read_csv("data.csv")

dest_lat = data["dest_lat"]

dest_long = data["dest_long"]

origin_lat = data["origin_lat"]

origin_long = data["origin_long"]

l = len(dest_lat)

for i in range(l):

dist = math.sqrt((dest_lat[i]-origin_lat[i])**2+(dest_long[i]-origin_long[i])**2)

print(dist)

data["Distance"] = dist

data.to_csv("out.csv")