我真的希望你能提供帮助。
我正在研究以下内容,它找到了与特定房产最近的学校。
除最后一步外,一切正常。我在raw_data数据帧中定义“ Primary”字段的地方,它始终返回NaN,但是,如果我逐步执行,则变量Primary_Name确实会填充。
知道为什么会这样吗?
for index, row in raw_data.iterrows():
start = (row['lat'], row['long'])
for index, row in schools.iterrows():
schoolloc = (row['Latitude'], row['Longitude'])
schools.loc[index,'distance'] = geopy.distance.geodesic(start, schoolloc).km
schools.dropna()
primary = schools.where(schools['PhaseOfEducation (name)'] == 'Primary')
Nearest_Primary = primary[primary['distance'] == min(primary['distance'])]
Primary_Name = Nearest_Primary.iloc[0]['EstablishmentName']
raw_data.loc[index,'primary'] = Primary_Name