현재 pandas._libs.hashtable.Int64HashTable.get_item 라는 에러가 나서 진행이 안 되고 있다.

찾아보니 사람들마다 이유가 제각각이라 도대체 뭐가 문제인지 모르겠는 상황이다.

하루종일 해봤지만 해결책을 찾지 못했기에 일단 기록으로 남기고 더 찾아보도록 하겠다.



=============================== Python ===============================

import math
import pandas as pd



# 두 개의 경도 위도를 알 때 두 점 사이의 거리를 구하기

def getDistance(lat1, lon1, lat2, lon2):
a = 6378137.0
b = 6356752.314245
f = 1 / 298.257223563

L = math.radians(lon2 - lon1)

U1 = math.atan((1 - f) * math.tan(math.radians(lat1)));
U2 = math.atan((1 - f) * math.tan(math.radians(lat2)));
sinU1 = math.sin(U1)
cosU1 = math.cos(U1)
sinU2 = math.sin(U2)
cosU2 = math.cos(U2)
cosSqAlpha = float()
sinSigma = float()
cos2SigmaM = float()
cosSigma = float()
sigma = float()

# l == lambda
l = L
lambdaP = float()
iterLimit = 100

while True:

sinLambda = math.sin(l)
cosLambda = math.cos(l)
sinSigma = math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (
cosU1 * sinU2 - sinU1 * cosU2 * cosLambda))
if (sinSigma == 0):
return 0;

cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
sigma = math.atan2(sinSigma, cosSigma)
sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma
cosSqAlpha = 1 - sinAlpha * sinAlpha
cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha
C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
lambdaP = l
l = L + (1 - C) * f * sinAlpha * (
sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
if (iterLimit == 0) or ((math.fabs(l - lambdaP) > 1e-12) and (iterLimit > 0)):
break
iterLimit = iterLimit - 1

# end while

if (iterLimit == 0):
return 0

uSq = cosSqAlpha * (a * a - b * b) / (b * b)
A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (
cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (
-3 + 4 * cos2SigmaM * cos2SigmaM)))

s = b * A * (sigma - deltaSigma)
return s




# # # 소수점 둘째자리까지만 표현
# df = pd.read_csv("G:/deep/project/accident.csv", encoding="utf-8")
# # long = [float("{0:.2f}".format(data)) for data in df.Longitude]
# # df['Longitude'] = long
# # lat = [float("{0:.2f}".format(data)) for data in df.Latitude]
# # df['Latitude'] = lat
# # df.to_csv("G:/deep/project/accident.csv")
# from pprint import pprint
# list = [police_list for police_list in df.index]
# pprint(list)



import operator
import sys

df1 = pd.read_csv("G:/deep/project/bui.csv", encoding="utf-8")
df2 = pd.read_csv("G:/deep/project/accident.csv", encoding="ANSI")

df1 = df1[['Latitude', 'Longitude', 'spot']]
df2 = df2[['Latitude', 'Longitude']]


lat1 = df1['Latitude'] # 17개
long1 = df1['Longitude'] # 17개
lat2 = df2['Latitude'] # acci # 9000개
long2 = df2['Longitude'] # acci # 9000개
name_list = [name for name in df1.spot]

dist_a_to_b =[]

for a in range(0, len(df2['Latitude'])): # 9000
for b in range(0, len(df1['Latitude'])): # 17
if b == 0: # for이 다시 처음부터 돌면 dist={}를 초기화를 시켜서 새로운 accident 지점이 들어갈 수 있게 만든다.
dist = {}
distance = float("{0:.2f}".format(getDistance(lat1[a], long1[a], lat2[b], long2[b])))
# print("a:"+str(a)+",b:"+str(b)+",,"+str(distance))
dist[name_list[b]] = distance # dist에 key:value로 저장한다.
if b == 16:
sort = sorted(dist.items(), key=operator.itemgetter(1)) # value값을 비교해서 오름차순으로 정렬한다.
dist_a_to_b.append(sort[0][0]) # key값만 뽑아서 저장한다.
# print(dist_a_to_b)
# print(dist)
# if a == 3:
# sys.exit(0)

df2['spot'] = dist_a_to_b
df2.to_csv("G:/deep/project/accident.csv")

=============================== Python ===============================






=============================== Error ===============================

Traceback (most recent call last):

  File "G:/deep/test.py", line 107, in <module>

    distance = float("{0:.2f}".format(getDistance(lat1[a], long1[a], lat2[b], long2[b])))

  File "G:\deep\venv\lib\site-packages\pandas\core\series.py", line 767, in __getitem__

    result = self.index.get_value(self, key)

  File "G:\deep\venv\lib\site-packages\pandas\core\indexes\base.py", line 3118, in get_value

    tz=getattr(series.dtype, 'tz', None))

  File "pandas\_libs\index.pyx", line 106, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 114, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 958, in pandas._libs.hashtable.Int64HashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 964, in pandas._libs.hashtable.Int64HashTable.get_item

KeyError: 17

=============================== Error ===============================




+ Recent posts