python - 叶热图
问题描述
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
解决方案
#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
推荐阅读
- build - Azure 管道构建有时会返回错误
- android - Android 预览工具栏
- oracle - ORA-00900: 无效的 SQL 语句实体框架生成的 sql 脚本
- python - 如何在python的一个类中定义一个串口
- javascript - 刷新时未定义位置道具(ReactJS)
- wordpress - 如何更改 AWS wordpress 站点以使用域名而不是 IP 地址?
- php - '' php 之间匹配短语的正则表达式
- c++ - Moving keys out of std::map<> &&
- azure - 在 azure 上扩展多个 Kubernetes 节点池
- html - 为什么浏览器将“ ”解析为“ ”?