我第一次在Jupyter笔记本中调用地图时,地图会按预期显示,但是当我在最后一行中运行地图时,会显示一个较大的空白而不是地图。非常感谢您的帮助。
'''
import pandas as pd
import folium as fl
# read csv file into dataframe
df = pd.read_csv('./dsc-v2-mod1-final-project-dc-ds-career- \
042219/kc_house_data.csv')
map = fl.Map(location=[df['lat'].mean(), df['long'].mean()])
map # map displays as expected
# return different colors for folium markercolor based on house sale
# price
def marker_color(price):
if (price >= 77000.00) and (price <= 199999.00):
colr = 'yellow'
elif (price >= 200000.00) and (price <= 399999.00):
colr = 'green'
elif (price >= 400000.00) and (price <= 599999.00):
colr = 'blue'
elif (price >= 600000.00 ) and (price <= 799999.00):
colr = 'orange'
else:
colr = 'red'
# iterate over dataframe and get lat, long, and price and assign
# them to folium Marker as arguments
for index, row in df.iterrows():
fl.Marker([row['lat'],row['long']], \
icon=fl.Icon(color=marker_color(row['price']), \
icon_color='green')).add_to(map)
map # blank space is displayed instead of the map
'''