import requests import pandas as pd import csv data=pd.read_csv("input_file/latitude_longitude.csv",keep_default_na=False) # dh_id=data['dh_id'] # dh_latitude=data['dh_latitude'].tolist() # dh_longitude=data['dh_longitude'].tolist() # a_latitude=data['a_latitude'].tolist() # a_longitude=data['a_longitude'].tolist() def parse(lat1,lon1,lat2,lon2): url="https://barikoi.xyz/v1/api/distance/MjU3OTpHTjI3SUUzOThX/%s,%s/%s,%s"%(lon1,lat1,lon2,lat2) response = requests.get(url) return response.json() #parse(dh_latitude[0],dh_longitude[0],a_latitude[0],a_longitude[0]) with open('Distance.csv','w',newline='') as f: writer=csv.writer(f) cnt=0 writer.writerow(["dh_id","dh_latitude","dh_longitude","a_latitude","a_longitude","Distance_Km"]) for index,row in data.iterrows(): cnt+=1 ans=parse(row['dh_latitude'],row['dh_longitude'],row['a_latitude'],row['a_longitude']) without_km=ans['Distance'] without_km=without_km.replace(' KM','') writer.writerow([row['dh_id'],row['dh_latitude'],row['dh_longitude'],row['a_latitude'],row['a_longitude'],without_km]) print(cnt)