Recursion 基于位置坐标的叶面热图递归误差

Recursion 基于位置坐标的叶面热图递归误差,recursion,heatmap,folium,Recursion,Heatmap,Folium,我正试图用我的数据制作一张通过叶子的热图。下面是我的代码,但我一直收到一个错误声明:RecursionError:超过了最大递归深度,我不知道这意味着什么。有什么意见吗?下面是热图的代码 # Creating a dataframe of the 'month', 'day_of_week' and 'location' day_month = pd.DataFrame(df_criclean[['month', 'day_of_week','location']]) day_month.sor

我正试图用我的数据制作一张通过叶子的热图。下面是我的代码,但我一直收到一个错误声明:
RecursionError:超过了最大递归深度,我不知道这意味着什么。有什么意见吗?下面是热图的代码

# 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.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

我遇到了同样的问题,通过将纬度和经度值转换为浮点数解决了这个问题:

import folium
import numpy as np

plot = folium.Map(location=[40, -95], zoom_start=4)

coords = np.random.rand(1000,2) * 100

for lat, lon in coords:
  folium.Circle(location=[float(lat), float(lon)]).add_to(plot)

在我将坐标从
str
转换为
float

df['lat'] = df['lat'].astype(float).fillna(0)
df['long'] = df['long'].astype(float).fillna(0)

我也有同样的问题。我必须使用.to_numpy()方法将其转换为一个numpy数组才能使其工作。

Hmm我认为这与处理坐标的底层函数有关。在将数据传递给热图之前,您能否尝试将数据转换为列表列表?因此,我需要创建一个新的数据框,其中包含(a)纬度坐标;(b) 经度坐标;(c) 名为“位置”的组合坐标;和(d)分组计数。(有关说明,请参见下面的代码)。Folium heat map需要一个列表,所以您需要将其转换为一个列表,我使用count方法查找最常见的位置。代码运行平稳,根本不需要花费任何时间,我有超过300k的观察结果。
# These are the top 20 'coordinates' according to the data.

sns.set(font_scale=1.25)
f, ax = plt.subplots(figsize=(15,8))
sns.countplot(y='location', data=df_criclean, order=df_criclean.location.value_counts().iloc[:20].index)



# Here, I'm making a Dataframe of the locations and the count.  What you see below
# is the top 5 locations. 
# I want to use this for my folium map.

df1 = df_criclean.groupby(["lat", "long", "location"]).size().reset_index(name='count')
df1['location'] = df1['location'].str.replace(',', '')

# Sort the count from highest count with location to lowest.
print(df1.sort_values(by = 'count', ascending=False).head())

# The DataFrame not sorted.
print(df1.head())

# convert to (n, 2) nd-array format for heatmap

locationArr = df1[['lat', 'long']].as_matrix()

m = folium.Map(location=[42.32, -71.0589], zoom_start=12)
m.add_child(plugins.HeatMap(locationArr, radius=9))
m`
import folium
import numpy as np

plot = folium.Map(location=[40, -95], zoom_start=4)

coords = np.random.rand(1000,2) * 100

for lat, lon in coords:
  folium.Circle(location=[float(lat), float(lon)]).add_to(plot)
df['lat'] = df['lat'].astype(float).fillna(0)
df['long'] = df['long'].astype(float).fillna(0)