【发布时间】:2020-04-05 09:26:11
【问题描述】:
我曾尝试将我的代码同时放入 Jupyter notebook 和 Google Colab,但是一旦我解决了我的代码中的所有错误,我不会只是在输出中看到一个空白屏幕。当我在将热图数据集放在上面之前只使用地图运行代码时,它可以工作。我使用https://alysivji.github.io/getting-started-with-folium.html 来构建我的代码。 以下是数据集的链接: https://data.cityofnewyork.us/Public-Safety/NYPD-Arrest-Data-Year-to-Date-/uip8-fykc
我的完整代码如下。
here is what it looks like right now
import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import numpy as np
import folium
from folium import features
from folium import plugins
from folium.plugins import HeatMap
from folium.plugins import MarkerCluster
print("Setup Complete")
crime_filepath = "arrestdata.csv"
crime_data = pd.read_csv (crime_filepath, index_col = "ARREST_DATE")
crime_data.head()
#this is the section that doesn't work
m = folium.Map([40.7128, -74.0060], zoom_start=10.3)
m #this and the line above properly creats a blank map
for index, row in crime_data.iterrows():
folium.CircleMarker([row['Latitude'],row['Longitude']],
radius=15,
fill_color="#3db7e4",).add_to(m)
my_map = crime_data[['Latitude', 'Longitude']].values
m.add_child(plugins.HeatMap(my_map, radius=15))
m
【问题讨论】:
-
你能提供
arrestdata.csv文件或它的摘录吗?否则,您的问题无法重现。 -
这里是数据集的链接。 data.cityofnewyork.us/Public-Safety/…
标签: pandas numpy jupyter-notebook heatmap folium