Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 试着用Folium CircleMaker绘制一幅图_Python_Python 3.x_Folium_Density Plot - Fatal编程技术网

Python 试着用Folium CircleMaker绘制一幅图

Python 试着用Folium CircleMaker绘制一幅图,python,python-3.x,folium,density-plot,Python,Python 3.x,Folium,Density Plot,我发现了一个非常有趣的帖子,我正在努力适应我的数据。这是这篇文章的链接 下面是我正在测试的代码 import pandas as pd import gmplot import matplotlib.pyplot as plt import folium from folium import plugins import seaborn as sns df = pd.read_csv('C:\\Users\\ryans\\OneDrive\\Desktop\\business.csv')

我发现了一个非常有趣的帖子,我正在努力适应我的数据。这是这篇文章的链接

下面是我正在测试的代码

import pandas as pd
import gmplot
import matplotlib.pyplot as plt
import folium
from folium import plugins
import seaborn as sns

df = pd.read_csv('C:\\Users\\ryans\\OneDrive\\Desktop\\business.csv')

m = folium.Map([43.7181557,-79.5181415], zoom_start=11)
m

new_df = df[['longitude', 'latitude', 'address']].copy()
new_df.dtypes

# mark each station as a point
for index, row in df.iterrows():
    print(row)
    folium.CircleMarker([new_df['latitude'], new_df['longitude']],
                        radius=15,
                        popup=new_df['address'],
                        fill_color="#3db7e4", # divvy color
                       ).add_to(m)

# convert to (n, 2) nd-array format for heatmap
stationArr = df[['latitude', 'longitude']].to_numpy()

# plot heatmap
m.add_children(plugins.HeatMap(stationArr, radius=15))
m
我得到了这个错误

ValueError: Location should consist of two numerical values, but 0       33.522143
1       43.605499
2       35.092564
3       33.455613
4       35.190012
   
9994    43.629300
9995    36.219236
9996    36.035749
9997    36.148016
9998    43.779707
Name: latitude, Length: 9999, dtype: float64 of type <class 'pandas.core.series.Series'> is not convertible to float.
最后,这里是我的新的_df的一个示例

       longitude   latitude                         address
0    -112.018481  33.522143     2818 E Camino Acequia Drive
1     -79.652289  43.605499            30 Eglinton Avenue W
2     -80.859132  35.092564       10110 Johnston Rd, Ste 15
3    -112.395596  33.455613   15655 W Roosevelt St, Ste 237
4     -80.887223  35.190012  4209 Stuart Andrew Blvd, Ste F
         ...        ...                             ...
9994  -79.625725  43.629300           1135A Crestlawn Drive
9995 -115.278133  36.219236               3240 N Durango Dr
9996 -115.153343  36.035749       7400 Las Vegas Blvd S Ofc
9997 -115.164513  36.148016                2101 Western Ave
9998  -79.418050  43.779707     28 Finch Avenue W, Unit 109

我如何解决这个问题呢?

在玩了一点之后,我想到了这个

X = df[['longitude', 'latitude', 'name']].copy()
# mark each station as a point
for index, row in X.iterrows():
    folium.CircleMarker([row['latitude'], row['longitude']],
                        radius=15,
                        popup=row['name'],
                        fill_color="#3db7e4", # divvy color
                       ).add_to(m)

# convert to (n, 2) nd-array format for heatmap
stationArr = df[['latitude', 'longitude']].to_numpy()

# plot heatmap
m.add_child(plugins.HeatMap(stationArr, radius=15))
m
这似乎很管用

我从来没有理解过这些不是真实错误的“假错误”。错误:无法转换为浮点。嗯,它已经是一个浮动,所以机器不应该试图进行某种转换

X = df[['longitude', 'latitude', 'name']].copy()
# mark each station as a point
for index, row in X.iterrows():
    folium.CircleMarker([row['latitude'], row['longitude']],
                        radius=15,
                        popup=row['name'],
                        fill_color="#3db7e4", # divvy color
                       ).add_to(m)

# convert to (n, 2) nd-array format for heatmap
stationArr = df[['latitude', 'longitude']].to_numpy()

# plot heatmap
m.add_child(plugins.HeatMap(stationArr, radius=15))
m