经济复杂性观察站的api包装
oec的Python项目详细描述
<1>经济复杂性观测台Python包装材料API
语言:python 3
数据源:Observatory for Economic Complexity (OEC)
安装
pip install oec
用法
从oec获取数据
import oec
# Set parameters in accordance with API documentation
params = {'classification': 'hs92',
'trade_flow': 'export',
'year': 2015,
'origin': 'egy',
'destination': 'all',
'product': 'show'}
list_of_countries = oec.get_countries()
list_of_products = oec.get_products(params['classification'])
list_of_exports = oec.get_trade(**params)
这些函数返回字典的每个列表。这些词典中的每一个都代表一行数据(例如,一个国家或产品)。这些词典的字段表示数据的“列”。如果将数据输出到csv文件中,则更容易可视化。
导出到csv
oec.data_to_csv(list_of_dictionaries, 'results.csv')
然后,可以在您选择的电子表格编辑器中打开这些csv文件以进行进一步分析。
生成可视化的链接
>>> oec.url_visual(**params)
'http://atlas.media.mit.edu/en/visualize/tree_map/hs92/export/egy/all/show/2015/'
>>> oec.embed_visual(**params)
'<iframe src="http://atlas.media.mit.edu/en/visualize/embed/tree_map/hs92/export/egy/all/show/2015/" width=930 height=400></iframe>'
>>> oec.url_visual(**params, language='fr')
'http://atlas.media.mit.edu/fr/visualize/tree_map/hs92/export/egy/all/show/2015/'
文件
函数级文档和语言列表:请参阅^{python -m pydoc oec
oec api文档:https://atlas.media.mit.edu/api/
数据属性和字段名:https://github.com/alexandersimoes/oec/wiki/Attributes
致谢
感谢Alex Simoes为The Observatory for Economic Complexity的发展。这个模块是由Yahia Ali开发的,他与oec团队没有任何关联。