볼 트리에서 반경을 쿼리하여 데이터를 얻는 방법은 무엇입니까? 예를TypeError : unhashable type : 'numpy.ndarray'- 공 트리에서 반경을 쿼리하여 데이터 프레임에서 데이터를 가져 오는 방법은 무엇입니까?
from sklearn.neighbors import BallTree
import pandas as pd
bt = BallTree(df[['lat','lng']], metric="haversine")
for idx, row in df.iterrow():
res = df[bt.query_radius(row[['lat','lng']],r=1)]
위해 나는 반경 r=1
에 안양에서 해당 행을 싶어. 그러나 행
5183
(5219, 25)
5205
(5219, 25)
5205
(5219, 25)
5221
(5219, 25)
Traceback (most recent call last):
File "/Users/Chu/Documents/dssg2018/sa4.py", line 45, in <module>
df.loc[idx,word]=len(df.iloc[indices[idx]][df[word]==1])/\
IndexError: index 5221 is out of bounds for axis 0 with size 5219
그리고 코드를 반복 할 때 내가 범위를 벗어난 인덱스를받은 첫 번째 대답 오류가 아닌
bag_of_words = ['beautiful','love','fun','sunrise','sunset','waterfall','relax']
for idx,row in df.iterrows():
for word in bag_of_words:
if word in row['caption']:
df.loc[idx, word] = 1
else:
df.loc[idx, word] = 0
bt = BallTree(df[['lat','lng']], metric="haversine")
indices = bt.query_radius(df[['lat','lng']],r=(float(10)/40000)*360)
for idx,row in df.iterrows():
for word in bag_of_words:
if word in row['caption']:
print(idx)
print(df.shape)
df.loc[idx,word]=len(df.iloc[indices[idx]][df[word]==1])/\
np.max([1,len(df.iloc[indices[idx]][df[word]!=1])])
이 문서에 따르면, 외형 -.'bt.query_radius (행 [ "북", "LNG를 '] values.ravel()을, R = 1)' –
@ cᴏʟᴅsᴘᴇᴇᴅ 아니요, 생성자에서 전달 된 것과 같은 2_D 배열이 필요합니다. –
문제는 ndarray를 넣음으로써 행을 얻으려고합니까? 이 문제를 해결할 수있는 방법이 있습니까? – monotonic