惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
C
Check Point Blog
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
有赞技术团队
有赞技术团队
Latest news
Latest news
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
Project Zero
Project Zero
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
腾讯CDC
P
Proofpoint News Feed
L
LINUX DO - 热门话题
C
Cisco Blogs
P
Palo Alto Networks Blog
Vercel News
Vercel News
P
Privacy International News Feed
爱范儿
爱范儿
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
MyScale Blog
MyScale Blog
K
Kaspersky official blog
B
Blog RSS Feed
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
O
OpenAI News
博客园 - 叶小钗
量子位
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 最新话题
F
Fortinet All Blogs
N
News | PayPal Newsroom
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
N
News and Events Feed by Topic
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI

阿猪的博客

如何使用CNB构建Hexo项目并部署到腾讯云COS 好坑爹!派息后买入的股票怎么也扣股息税? 游哈尔滨 跨年往事 安装Ta-Lib时报错"Could not build wheels" 网站被恶意镜像了该怎么办 延迟退休正式到来!来看看有什么规定 我的基金怎么就被强制卖出了? Hexo-AlgoliaSearch插件报错“Error has occurred during indexing posts” 找工作避坑不完全指南 办理信用卡应该注意什么 华为Pad开启了“共享至电脑”,但是Windows下无法正常访问 webdriver-manager报错一例 Windows无法从环境变量中找到Python的正确位置 习大大2024年新年贺词 号外!号外!Twikoo可以直接屏蔽垃圾评论啦! 如何将Coding的代码仓同步到Github 博客被攻击了 华为Pad开启了“共享至电脑”,但是Ubuntu下无法正常访问 如何恢复Etcher刻录过的U盘 如何在Ubuntu下快速切换网络代理状态 在腾讯云函数中使用Pandas报错`No module named 'numpy.core._multiarray_umath'` 对空的DataFrame使用apply方法未得到预期结果 SQLite中使用关键字作为列名称导致报错 Logging模块重复输出内容的原因及解决方法 如何在Selenium中保持网站的登录状态 如何下载与Chrome浏览器的版本相匹配的ChromeDriver 如何下载旧版本Python的安装包 如何为不同的Python项目自动选择不同的解释器 使用腾讯云函数搭建Web站点 WordPress CORS问题一例 踩坑阿里云函数计算搭建WordPress 在AWS Amplify中部署Jekyll站点 让Chirpy主题支持折叠展示代码块 实现ChatGPT的文字输出效果 python中使用'''注释代码后引起报错 使用python自带的email模块解析邮件 如何通过复权因子计算复权价格 国内量化平台不完全汇总
使用pandas_bokeh在地图上显示数据
阿猪 · 2022-11-01 · via 阿猪的博客

  pandas_bokeh的MapPlots方法只需要点坐标即可定位,支持直接从csv等常规文件中读取数据。但是功能更丰富的GeoPlots方法是基于GeoJson格式的数据的,需要从GeoJson文件中读取位置数据,如果直接向dataframe写入位置数据,则pandas_bokeh会在读取数据的时候报错Type Error: Unhashable type: 'list'
  对于type类型为Feature的GeoJson文件,官方给出的基本结构示例如下:

  一级key包含type、geometry、properties。其中geometry中存放位置信息,包含type、coordinates两个key。type包含Point(点)、Polygon(多个点连接而成的多边形)、Multipolygon(多个Polygon,比如印尼有很多个岛屿,存储其国土形状信息就需要多个Polygon)。properties存放其他各类数据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{
"type": "Feature",
"properties":
{
"FIPS": "AC",
"ISO2": "AG",
"ISO3": "ATG",
"UN": 28,
"NAME": "Afghanistan",
"AREA": 44,
"POP2005": 83039,
"POP2006": 93039,
"REGION": 19,
"SUBREGION": 29,
"LON": -61.783,
"LAT": 17.078
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [ [ [ [ -61.686668, 17.024441000000152 ], [ -61.887222, 17.105274 ], [ -61.794449, 17.163330000000101 ], [ -61.686668, 17.024441000000152 ] ] ], [ [ [ -61.729171999999892, 17.608608 ], [ -61.853058, 17.583054000000104 ], [ -61.873062, 17.703888 ], [ -61.729171999999892, 17.608608 ] ] ] ] }
},

{ "type": "Feature", "properties": { "FIPS": "AL", "ISO2": "AL", "ISO3": "ALB", "UN": 8, "NAME": "Albania", "AREA": 2740, "POP2005": 3153731, "POP2006": 4153731, "REGION": 150, "SUBREGION": 39, "LON": 20.068, "LAT": 41.143 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 19.436214, 41.021065 ], [ 19.600555, 41.796661 ], [ 19.367771, 41.848999 ], [ 19.645832, 42.61805 ], [ 20.071423, 42.560913 ], [ 20.589642, 41.882187 ], [ 20.492775, 41.331108 ], [ 20.82111, 40.908882 ], [ 20.98349, 40.855888 ], [ 20.671944, 40.098053000000121 ], [ 20.010029, 39.6912 ], [ 19.863052, 40.039719 ], [ 19.288609, 40.417496 ], [ 19.478611, 40.350273 ], [ 19.436214, 41.021065 ] ] ] } }
]

}

  一级key一般包含type、crs、features。猜测crs应该是声明features中keys、values的结构的。features的数据的形式类似于list,可以根据自己的需要放入一个或多个嵌套的类似dict结构的数据。比如你需要画5个国家,显示每个国家的人口数据,那么就对应5个。

  这里是重点,你想要显示在地图上的数据,都需要放到feature下每个嵌套”dict”的properties中。例如上边示例中的POP2005、POP2006就是自己加进去的。Pandas_Bokeh也是在properties里寻找你要它显示的数据。

  Pandas_Bokeh读取完GeoJson数据后,是以DataFrame形式存放的。所以如果你嫌弃在GeoJson文件中写入不方便,理论上也可以使用传统的csv文件、数据库等方式储存自己的数据,然后在这个DataFrame中增加一列或多列,把你自己的数据放入这个DataFrame。

  一个不明觉厉的网站,提供World Borders Dataset的shapefile下载,自行转换为GeoJson格式后即可使用。可以通过Pandas_Bokeh在地图上轻松绘制每个国家的形状。