gpt4 book ai didi

recursion - 基于位置坐标的 Folium 热图递归误差

转载 作者:行者123 更新时间:2023-12-04 17:39:22 25 4
gpt4 key购买 nike

我正在尝试使用我的数据通过 folium 制作热图。下面是我的代码,但我不断收到错误消息:RecursionError: maximum recursion depth exceeded我不知道这意味着什么。任何输入?下面是热图的代码。

# Creating a dataframe of the 'month', 'day_of_week' and 'location' day_month = pd.DataFrame(df_criclean[['month', 'day_of_week','location']])
day_month.sort_values('month', ascending = False).head(10)

# Trying to use folium to make a heatmap of the data I have in 'day_month'

map = folium.Map(location=[42.3601, -71.0589], [enter image description here][1]tiles='cartodbpositron', zoom_start=1)
HeatMap(day_month['location']).add_to(map)

最佳答案

我也有这个“错误”,我认为它与类型 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

关于recursion - 基于位置坐标的 Folium 热图递归误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55210428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com