Giter Site home page Giter Site logo

tishacy / worlddataatlasspider Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 165 KB

Spider of world data atlas (knoema).

Home Page: https://nbviewer.jupyter.org/github/Tishacy/WorldDataAtlasSpider/blob/master/handbook.ipynb

License: MIT License

Python 19.95% Jupyter Notebook 80.05%
knoema spider data-atlas

worlddataatlasspider's Introduction

World Data Atlas (Knoema) Spider

(Unofficial API)通过 Knoema 获取 某国家/地区某指标不同年份 的数据。

戳这里看使用示例

目录树如下:

.
├── demo.py                     # 简单的demo
├── demo.png
├── handbook.ipynb              # handbook (jupyter notebook)
├── knoema                      # 爬虫主目录
│   ├── __init__.py
│   ├── knoema.py               # 爬虫主文件
│   ├── source_data             # 爬虫源数据
│   │   ├── countries.json
│   │   ├── get_count_id.py
│   │   ├── get_indic_id.py
│   │   └── indicators.json
│   └── utils.py                # 爬虫工具函数模块
├── README.md
├── LICENSE
└── requirements.txt

Pre-requirements

  1. 克隆至本地。

    $ git clone https://github.com/Tishacy/WorldDataAtlasSpider.git
    $ cd WorldDataAtlas
  2. 依赖库如下:

    mspider==0.2.5
    numpy==1.13.3
    pandas==0.24.2
    requests==2.18.4
    matplotlib==3.0.1
    beautifulsoup4==4.7.1

    安装依赖:

    $ pip install -r requirements.txt

Usage

Quick start

获取美国的GDP数据。

  1. 在仓库主目录下新建python文件或打开IPython console。

  2. 导入knoema模块。

    from knoema.knoema import Country
    from knoema.utils import *
  3. 创建Country对象。

    US = Country('USA')
    # 或者使用国家/地区全称
    # US = Country('United-States-of-America')
  4. 获取美国往年GDP数据。

    US.fetch_data('GDP')

    得到:

    [{'Indicator': 'GDP',
      'Time': '1980-01-01T00:00:00Z',
      'Value': 2857.33,
      'Unit': 'U.S. dollars, Billions',
      'RegionId': 'US',
      'country': 'United States'},
     {'Indicator': 'GDP',
      'Time': '1981-01-01T00:00:00Z',
      'Value': 3207.03,
      'Unit': 'U.S. dollars, Billions',
      'RegionId': 'US',
      'country': 'United States'},
        ...
     {'Indicator': 'GDP',
      'Time': '2018-01-01T00:00:00Z',
      'Value': 20494.05,
      'Unit': 'U.S. dollars, Billions',
      'RegionId': 'US',
      'country': 'United States'}]
  5. 获取2015年美国GDP数据。

    US.query('GDP', '2015')

    得到:

    [{'Time': '2015-01-01T00:00:00Z',
      'country': 'United States',
      'RegionId': 'US',
      'subject': 'Gross domestic product, current prices (U.S. dollars)',
      'Frequency': 'A',
      'Value': 18219.3,
      'Unit': 'U.S. dollars, Billions',
      'Scale': 1}]

运行demo

demo.py:获取**和美国的GDP数据并绘制图像。

$ python3 demo.py

若见下图,则运行成功。

Figure of demo

License

Copyright (c) 2019 tishacy.

Licensed under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.