在Python中的Nominatim地理编码在设置WithCopyWarning时失败。

问题描述 投票:0回答:1

在Google Colab.上遇到了问题。

我在数据框df1中有一列 "LOCATION"。

df1.LOCATION
0    Cresent Lake Rd,Acworth,NH
1    Old Charlestown Tpk,Acworth,NH
2    Grout Hill Rd,Acworth,NH
3    Cold Pond Rd,Acworth,NH
4    Acworth Rd,Acworth,NH
Name: LOCATION, dtype: object

然后我试图使用Nominatim对上述列进行地理编码,如下所示。

Locator=Nominatim(user_agent='myGeocoder')
geocode=RateLimiter(locator.geocode, min_delay_seconds=5)
try:
    df1['GPS_LOC'].location=df1['LOCATION'].apply(geocode)
except:
    df1['GPS_LOC']='xxx,xxx,xxx'

这给了我以下信息。

usrlocallibpython3.6dist-packagesipykernel_launcher.py:10: SettingWithCopyWarning: 一个值正试图在DataFrame的一个片断的副本上设置。 请尝试使用.loc[row_indexer,col_indexer] = value来代替,参见文档中的注意事项。https:/pandas.pydata.orgpandas-docsstableuser_guideindexing.html#returning-a-view-versus-a-copy。 #在加载东西的时候,从sys.path中删除CWD。

而当我看到 df1.GPS_LOC我可以看到异常处理程序被调用了。

0    xxx,xxx,xxx
1    xxx,xxx,xxx
2    xxx,xxx,xxx
3    xxx,xxx,xxx
4    xxx,xxx,xxx
Name: GPS_LOC, dtype: object

谁能告诉我怎么做 https:/pandas.pydata.orgpandas-docsstableuser_guideindexing.html#returning-a-view-versus-a-copy。 将帮助我克服这个问题。

python dataframe geocoding nominatim
1个回答
0
投票

是的,我的一个愚蠢的错误

df1['GPS_LOC'].location=df1['LOCATION'].apply(geocode)`

已更正为

df1['GPS_LOC']=df1['LOCATION'].apply(geocode)
© www.soinside.com 2019 - 2024. All rights reserved.