我的数据只有三列,时间、经度和纬度,想要后一时间点的经纬度减去前一时间点的经纬度求得两点之间的距离,应该怎样修改下面的代码
#根据经纬度计算距离
from math import radians, cos, sin, asin,sqrt
import pandas as pd
def geodistance(lon1, lat1, lon2, lat2):
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # 将经纬度转化为弧度
dlon = lon2-lon1
dlat = lat2-lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
distance = 2*asin(sqrt(a))*6371
return distance
place_name = pd.read_csv(r'lon_lat.csv',encoding='GBK')
hangshu = place_name.shape[0]
distance_list = []
for i in range(hangshu):
print(i,'/',hangshu)
lon1 = place_name.iloc[i,1]
lat1 = place_name.iloc[i,2]
lon2 = place_name.iloc[i,3]
lat2 = place_name.iloc[i,4]
distance_start_end = geodistance(lon1=lon1,lat1=lat1,lon2=lon2,lat2=lat2)
distance_list.append(distance_start_end)
df = pd.DataFrame({'date':place_name.iloc[:,0],'lon1':place_name.iloc[:,1],'lat1':place_name.iloc[:,2],'lon2':place_name.iloc[:,3],'lat2':place_name.iloc[:,4],'distance':distance_list})
df.to_csv('distance_geo_data_gaode.csv',encoding='GBK',index=False)