ボールツリーから半径を照会してデータを取得する方法は?例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
であるDFでそれらの行を取得したいです。しかし、それは
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])])
1) ' –
@cᴏʟᴅsᴘᴇᴇᴅいいえ、コンストラクタで渡された配列と同じ2_D配列が必要です。 –
問題はndarrayを入れて行を取得しようとしていますか?私がこれを解決できる方法はありますか? – monotonic