创建英国热图

时间:2019-01-21 15:41:56

标签: python pandas heatmap choropleth

我有一个英国数据的数据框,看起来像这样:

longitude   latitude     region           priority
51.307733   -0.75708898  South East       High
51.527477   -0.20646542  London           Medium
51.725135   0.4747223    East of England  Low

此数据帧长数千行。我希望按区域和颜色强度细分的英国热图取决于每个区域的优先级。

我想知道将其转变为英国热点图的最佳方法。我已经尝试过geoPandas和Plotly,但我对这些都不了解。这些是执行此操作的最佳方法,还是那里提供了一个工具,您可以简单地将数据上传到该工具并将其绘制出来?谢谢!

1 个答案:

答案 0 :(得分:0)

对于这种工作,我过去常使用叶片,这对于处理地图非常有用, 但是对于heatMap,您必须将“ priority”列作为float!

import folium
from folium import plugins
from folium.plugins import HeatMap


my_map = folium.Map(location=[51.5074, 0.1278],
                    zoom_start = 13) # for UK 


your_dataframe['latitude'] = your_dataframe['latitude'].astype(float)
your_dataframe['longitude'] = your_dataframe['longitude'].astype(float)
your_dataframe['priority'] = your_dataframe['priority'].astype(float)


heat_df = your_dataframe[['latitude', 'longitude','priority']]
heat_df = heat_df.dropna(axis=0, subset=['latitude','longitude','priority'])

# List comprehension to make out list of lists
heat_data = [[row['latitude'],row['longitude'],row['priority']] for index, row in heat_df.iterrows()]

my_map.add_children(plugins.HeatMap(heat_data))
my_map.save('map.html')

然后必须使用浏览器打开map.html