У меня также есть эта "ошибка" , я думаю, что она связана с переменными типа object
вместо float64
или других базовых типов (вместо этого в моем наборе данных было много пробелов ""
действительных координат GPS).
#> ./folium-test.py
--------------------
_id city daily_rain date ... wind_degrees wind_dir wind_speed wind_string
0 {'$oid': '5571aaa8e4b07aa3c1c4e231'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 4.8 NaN
1 {'$oid': '5571aaa9e4b07aa3c1c4e232'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 1.6 NaN
2 {'$oid': '5571aaa9e4b07aa3c1c4e233'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 11.3 NaN
3 {'$oid': '5571aaa9e4b07aa3c1c4e234'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 13 NaN
4 {'$oid': '5571aaa9e4b07aa3c1c4e235'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 5 NaN
[5 rows x 18 columns]
(500, 18)
--------------------
0 8.48402346662349
1 8.15408706665039
2 9.81855869293213
3 9.83495235443115
4 9.92164134979248
5 9.26684331789147
6 9.59504252663464
7 9.07091170549393
8 8.99822786450386
9 8.9606299996376
10 8.93120750784874
11 9.02073669538368
12 8.912937
13
...
498 8.912937
499
Name: longitudine, Length: 500, dtype: object
0 44.3720632234234
1 43.9720632409982
2 44.1090045985169
3 44.1142735479457
4 44.145446252325
5 44.3377021234296
6 44.3773853328621
7 44.3798960485217
8 44.4051013957662
9 44.4094088501931
10 44.4160476104163
11 44.4527250625144
12 44.516321
13
...
498 44.516321
499
Name: latitudine, Length: 500, dtype: object
Traceback (most recent call last):
File "./folium-test.py", line 89, in <module>
folium.Marker([row["latitudine"], row["longitudine"]], popup=row["temperatura"]).add_to(marker_cluster)
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/map.py", line 258, in __init__
self.location = _validate_coordinates(location)
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 53, in _validate_coordinates
if _isnan(coordinates):
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 79, in _isnan
return any(math.isnan(value) for value in _flatten(values))
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 79, in <genexpr>
return any(math.isnan(value) for value in _flatten(values))
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 71, in _flatten
for j in _flatten(i):
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 71, in _flatten
for j in _flatten(i):
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 71, in _flatten
for j in _flatten(i):
[Previous line repeated 982 more times]
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 70, in _flatten
if _is_sized_iterable(i):
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/site-packages/folium/utilities.py", line 32, in _is_sized_iterable
return isinstance(arg, abc.Sized) & isinstance(arg, abc.Iterable)
File "/mnt/ros-data/venvs/meteo-viz/lib/python3.7/abc.py", line 139, in __instancecheck__
return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison
Но если я добавлю эти строки в свой код, folium
будет работать нормально (даже для больших наборов данных):
df['longitudine'] = df['longitudine'].replace(r'\s+', np.nan, regex=True)
df['longitudine'] = df['longitudine'].replace(r'^$', np.nan, regex=True)
df['longitudine'] = df['longitudine'].fillna(-0.99999)
df['longitudine'] = pd.to_numeric(df['longitudine'])
df['latitudine'] = df['latitudine'].replace(r'\s+', np.nan, regex=True)
df['latitudine'] = df['latitudine'].replace(r'^$', np.nan, regex=True)
df['latitudine'] = df['latitudine'].fillna(-0.99999)
df['latitudine'] = pd.to_numeric(df['latitudine'])
Это вывод:
#> ./folium-test.py
--------------------
_id city daily_rain date ... wind_degrees wind_dir wind_speed wind_string
0 {'$oid': '5571aaa8e4b07aa3c1c4e231'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 4.8 NaN
1 {'$oid': '5571aaa9e4b07aa3c1c4e232'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 1.6 NaN
2 {'$oid': '5571aaa9e4b07aa3c1c4e233'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 11.3 NaN
3 {'$oid': '5571aaa9e4b07aa3c1c4e234'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 13 NaN
4 {'$oid': '5571aaa9e4b07aa3c1c4e235'} NaN 0 2015-06-05 15:56:00 ... NaN NaN 5 NaN
[5 rows x 18 columns]
(500, 18)
--------------------
0 8.484023
1 8.154087
2 9.818559
3 9.834952
4 9.921641
5 9.266843
6 9.595043
7 9.070912
8 8.998228
9 8.960630
10 8.931208
11 9.020737
12 8.912937
13 -0.999990
...
498 8.912937
499 -0.999990
Name: longitudine, Length: 500, dtype: float64
0 44.372063
1 43.972063
2 44.109005
3 44.114274
4 44.145446
5 44.337702
6 44.377385
7 44.379896
8 44.405101
9 44.409409
10 44.416048
11 44.452725
12 44.516321
13 -0.999990
...
498 44.516321
499 -0.999990
Name: latitudine, Length: 500, dtype: float64
1 43.9720632409982 8.154087066650389 30.6