Python资源共享群:484031800
从 https://datahub.io/core/gdp#data 下载得到json文件。
大家在学python的时候肯定会遇到很多难题,以及对于新技术的追求,这里推荐一下我们的Python学习扣qun:784758214,这里是python学习者聚集地!!同时,自己是一名高级python开发工程师,从基础的python脚本到web开发、爬虫、django、数据挖掘等,零基础到项目实战的资料都有整理。送给每一位python的小伙伴!每日分享一些学习的方法和需要注意的小细节
# country_code.py 获取国家二字代码
# 从pygal.maps.world模块导入{国家代码:国家名字}的列表
from pygal.maps.world import COUNTRIES
import json
# 创建找国家代码的函数
def get_country_code(country):
for code, name in COUNTRIES.items():
if name == country:
return code
return None
if __name__ == '__main__':
filename = 'world_GDP.json'
with open(filename) as f:
data = json.load(f)
for dic in data:
for key in dic:
if key == 'Year':
if dic[key] == 2016:
country = dic['Country Name']
print(country + ': ', get_country_code(country))
# world_GDP

本文介绍如何使用Python从数据hub.io获取2016年世界GDP数据,并通过教程指导读者绘制全球GDP地图,适合Python初学者及数据可视化爱好者学习。
最低0.47元/天 解锁文章
268

被折叠的 条评论
为什么被折叠?



