0
팬더 데이터 프레임에 K- 평균 클러스터링을 적용하고 있습니다.팬더 데이터 프레임에 람다 함수를 적용하는 동안 발생하는 키 오류
1945 return self._engine.get_loc(key)
1946 except KeyError:
-> 1947 return self._engine.get_loc(self._maybe_cast_indexer(key))
1948
1949 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4154)()
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4018)()
pandas\hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12368)()
pandas\hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12322)()
KeyError: (0, 'occurred at index 0')
누군가가 오류의 원인과 어떻게 같은 설명을 제공하시기 바랍니다 수 : 람다 기능을 사용하는 동안
def assign_to_cluster(row):
lowest_distance = -1
closest_cluster = -1
for cluster_id, centroid in centroids_dict.items():
df_row = [row['PPG'],row['ATR']]
euclidean_distance = calculate_distance(centroids, df_row)
if lowest_distance == -1:
lowest_distance = euclidean_distance
closest_cluster = cluster_id
elif euclidean_distance < lowest_distance:
lowest_distance = euclidean_distance
closest_cluster = cluster_id
return closest_cluster
point_guards['CLUSTER'] = point_guards.apply(lambda row: assign_to_cluster(row), axis=1)
그러나 나는 다음과 같은 오류가 발생합니다 : 클러스터 할당 기능은 다음과 같다 그것을 해결할 수 있습니까? 추가 정보가 필요하면이 게시물에 회신 해주십시오. 그리고 형식에 대해 사과드립니다. StackOverflow에서 질문을하는 것은 이번이 처음입니다.
point_guards.head() 란 무엇입니까? – putonspectacles
참조 : http://stackoverflow.com/questions/16353729/pandas-how-to-use-apply-function-to-multiple-columns – putonspectacles
@putonspectacles : point_guards는 내가 작업하고있는 팬더 데이터 프레임의 이름입니다. head() 함수는 데이터 프레임의 처음 10 개 행을 인쇄합니다. 적어도 그것은 그렇게 생각합니다. –