일부 위치의 위도와 경도가 포함 된 lat_long이라는 데이터 프레임이 있습니다. 나는 각각의 다음 위치의 차이점을 찾고 싶다. 예제 haversine 함수를 사용할 때 오류가 발생합니다. KeyError : ('1', 색인 0에 u'curred 됨).데이터 프레임에서 Haversine 함수로 데이터를 호출하는 방법
1 2
0 -6.081689 145.391881
1 -5.207083 145.788700
2 -5.826789 144.295861
3 -6.569828 146.726242
4 -9.443383 147.220050
def haversine(row):
lon1 = lat_long['1']
lat1 = lat_long['2']
lon2 = row['1']
lat2 = row['2']
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
c = 2 * arcsin(sqrt(a))
km = 6367 * c
return km
lat_long['distance'] = lat_long.apply(lambda row: haversine(row), axis=1)
lat_long
당신이 뜻하는 일 – Batman
다음 행마다 차이점을 찾고 싶습니다. –
@AmyRose, [that] (http://stackoverflow.com/a/40453439/5741205) 원하는게 뭐야? – MaxU