Folium地理映射导致TypeError:必须为实数,而不是str while

时间:2018-12-26 19:38:30

标签: python-3.x folium geomap

我在XML文件中存储了大量坐标。它们用Python解析并存储到Pandas DataFrame中,我想用它在地图上映射所有这些坐标。

整个解析工作正常,即使DataFrame是正确的。我试图通过AUR安装大叶草,但是同样的错误。

#!/usr/bin/env python
import pandas as pd
import requests
from xml.etree import ElementTree
import numpy as np
import folium

xml_data = "coords.xml"

tree = ElementTree.parse(xml_data)
counter = tree.find('counter')

id = []
name = []
latitude = []
longitude = []

for c in tree.findall('counter'):
    id.append(c.attrib['id'])
    name.append(c.find('name').text)
    latitude.append(c.find('latitude').text)
    longitude.append(c.find('longitude').text)

df_counters = pd.DataFrame(
    {'ID' : id,
    'Name' : name,
    'latitude' : latitude,
    'longitude' : longitude
    })
df_counters.head()

locations = df_counters[['latitude', 'longitude']]
locationlist = locations.values.tolist()

map = folium.Map(location=[47.3, 5.2], zoom_start=10)
for point in range(0, len(locationlist)):
    folium.Marker(locationlist[point], popup=df_counters['Name'][point]).add_to(map)
map

已解析的xml文件如下所示:

<counter id="10084">
  <name>DSC_00458.JPG</name>
  <latitude>47.4340525</latitude>
  <longitude>8.208285</longitude>
</counter>
<counter id="10085">
  <name>DSC_01287.JPG</name>
  <latitude>47.3563725</latitude>
  <longitude>12.449092499999999</longitude>
</counter>

我想达到的是,我将所有这些坐标都映射为点在地图上。 但是,除了获取Folium的QT-Window之外,stacktrace中仅显示以下消息:

Traceback (most recent call last):
  File "./map.py", line 40, in <module>
    folium.Marker(locationlist[point], popup=df_counters['Name'][point]).add_to(map)
  File "/home/rtfm/.local/lib/python3.7/site-packages/folium/map.py", line 252, in __init__
    self.location = _validate_coordinates(location)
  File "/home/rtfm/.local/lib/python3.7/site-packages/folium/utilities.py", line 39, in _validate_coordinates
    if _isnan(coordinates):
  File "/home/rtfm/.local/lib/python3.7/site-packages/folium/utilities.py", line 65, in _isnan
    return any(math.isnan(value) for value in _flatten(values))
  File "/home/rtfm/.local/lib/python3.7/site-packages/folium/utilities.py", line 65, in <genexpr>
    return any(math.isnan(value) for value in _flatten(values))
TypeError: must be real number, not str

我不知道堆栈跟踪的实际原因在哪里。 即使我尝试从此处尝试原始示例:https://georgetsilva.github.io/posts/mapping-points-with-folium/ 我又收到了相同的错误消息。

0 个答案:

没有答案