У меня есть два DataFrame здесь, один из них df1, а другой df2, и задача состоит в том, чтобы найти все элементы в df2 ['LON'], df2 ['LAT'], разница между которыми между df1 ['pickuplongitude '] и df1 [' pickuplaitude '] меньше 0,06 и больше -0,06, если элементы находятся, то добавьте df2 [' BANK '] в df1, поэтому я написал для l oop в функции apply ( ), как показано на следующем рисунке.
def s(df1):
p1=df1['pickup_longitude']
p2=df1['pickup_latitude']
pickupbank=[]
for i in range(len(df2)):
y=df2.at[i,'LON']
x=df2.at[i,'LAT']
if abs(math.acos((math.sin(y)*math.sin(p1))+math.cos(y)*math.cos(p1)*math.cos(x-p2))*6371.004*0.6213712)<0.06:
s=df2.at[i:'BANK']
pickupbank=pickupbank.append(s)
else:
continue
return pickupbank
df1.loc[:,pb]=df1.apply(s,axis=1)
однако отображается ошибка:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 3