ポイントを持つデータフレームがあります。最初の2つの列は位置です。私は別のポイントへの近接点に基づいてデータをフィルタリングしています。私は、すべての点の距離をcdistで計算し、この結果をフィルタリングして、距離が0.5より小さい点のインデックスを見つけます。私は同じポイント距離[n、n] = distance [n、n]を常にゼロに等しいと比較するための削除インデックスを削除するために、これらのインデックス上で2つのミニフィルタを最初に実行しなければなりません。 。同様の距離比較距離[n、m] =距離[m、n]のためにindesを削除します。基本的には削除する必要があるポイントの数が2倍になるので、半分をフィルタリングするためにユニークに使用します。pandasデータフレームの行を行インデックスの配列に基づいて削除するには
私の質問loc_find
は削除する必要がある行へのインデックスのnumpy配列です。この配列を使用して、データフレームの反復処理を行わずに、これらの行をパンダのデータフレームから削除するにはどうすればよいですか?
from scipy.spatial.distance import cdist
import numpy as np
import pandas as pd
# make points and calculate distances
east=data['easting'].values
north=data['northing'].values
points=np.vstack((east,north)).T
distances=cdist(points,points) # big row x row matrix
zzzz=np.where(distances<0.5)
loc_dist=np.vstack((zzzz[0],zzzz[1])).T #array of indices where points are
# to close together and will be filtered contains unwanted distance
# comparisons such as comparing data[1,1] with data[1,1] which is always zero
#since it is the same point. also distance [1,2] is same as [2,1]
#My code for filtering the indices
loc_dist=loc_dist.astype('int')
diff_loc=zzzz[0]-zzzz[1] # remove indices for comparing the same
#point distance [n,n] = distance [n,n]
diff_zero=np.where(diff_loc==0)
loc_dist_s=np.delete(loc_dist, diff_zero[0],axis=0)
loc_find=np.unique(loc_dist_s) # remove indices for similar distance
#comparisons distance [n,m] = distance [m,n]
'df.drop(loc_find)'はうまくいくはずです – EdChum
@EdChum loc_findに関する提案をお寄せいただきありがとうございます。 –