首页 > 解决方案 > 叶热图

问题描述

Folium 中的热图

我有一个包含房屋交易数据的数据框(有关房屋、位置和价格的元数据)。

我想制作一个代表价格的热图,而不是默认的频率。因此,交易价格高的区域会变得更加有色,反之亦然。

有人知道吗?我最好的猜测是将价格表示为行数,例如,如果一排是一个价格单位并且房子以 5 个单位出售,那么我需要将该行复制 5 次。但这根本不够计算友好(如果可能的话)。

谢谢!

这是我的数据的表示:

data = pd.DataFrame({"house_id" : [1, 2, 3, 4],
                     "latitude": [55.83, 55.79, 55.86, 55.85],
                     "longitude": [12.05, 12.10, 12.07, 12.09],
                     "price": [2000, 2100, 1500, 4500]})

这里是我用来用 Folium 生成热图的代码,它现在根据位置在#rows 方面出现的频率来产生“热”。

from folium import plugins
from folium.plugins import HeatMap

heat_data = [[row['latitude'],row['longitude']] for index, row in data.iterrows()]
map = folium.Map(location=[55.838913, 12.055415], zoom_start = 13)

# Plot it on the map
HeatMap(heat_data).add_to(map)

# Display the map
map

标签: pythonpandasgeospatialfolium

解决方案


#Import the Lib
from folium.plugins import HeatMap

#Make the list of Lat an Lng
lat = data.latitude.tolist()
lng = data.longitude.tolist()

#Create the Map
map = folium.Map(
    location=[55.838913, 12.055415],
    tiles='cartodbdark_matter',
    zoom_start=11
)
HeatMap(list(zip(lat, lng))).add_to(map)
map

推荐阅读