应用不起作用,列表仅显示 Python 中的 1 个项目和 Geopy城市

问题描述

我创建了一个代码来从 GEOPY 创建一个列表。@H_404_1@

它遍历 Excel 文件(包含所有纬度/经度的列)@H_404_1@

由于 API 为 Raw 提供了不同的名称,因此我使用 Try/Except 插入了所有可能性。@H_404_1@

一切看起来都不错,但结果只是列表中的一项,应该是 5,因为我的测试列表包含 5 行..@H_404_1@

import pandas as pd
from geopy.geocoders import Nominatim

arquivo = pd.read_excel(r'C:\Users\nando\OneDrive\Área de Trabalho\LatLon.xlsx')

geolocator = Nominatim(user_agent="geoapi",timeout=10)

listacidades= []

for index,row in arquivo.iterrows():
  coord = str(row['Concatenado'])

Location = geolocator.reverse(coord,language="en")

#print(Location.raw["address"])

try:
   cidade= (Location.raw['address']['town'])
except:
   try:
      cidade= (Location.raw['address']['city'])
   except:
      try:
         cidade =(Location.raw['address']['state'])
      except:
         try:
            cidade= (Location.raw['address']['municipality'])
         except:
            cidade="Nao enconTrado"

listacidades.append(cidade)

我的 Excel 表格:@H_404_1@

enter image description here

@H_404_1@

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)