【问题标题】:Nominatim Geocoding in Python Fails With SettingWithCopyWarningPython 中的 Nominatim 地理编码因 SettingWithCopyWarning 而失败
【发布时间】:2020-08-31 15:08:13
【问题描述】:

Google Colab 遇到问题。

我在数据框 df1 中有一个“位置”列:

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'

这给了我以下信息:

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:10: SettingWithCopyWarning: 试图在 DataFrame 中的切片副本上设置一个值。 尝试改用 .loc[row_indexer,col_indexer] = value 请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy # 在加载内容时从 sys.path 中删除 CWD。​​p>

当我查看 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.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy 将如何帮助我克服这个问题。

【问题讨论】:

    标签: python dataframe geocoding nominatim


    【解决方案1】:

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

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

    已更正为

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多