
今回は World Development Indicators のデータを使いたいと思います。

Data & Resources の Developer documentation に API の説明があります。
特に API Basic Call Structures にサンプルの URL がたくさん載っています。

まず、この World Development Indicators にどんなパラメータを指定する必要があるのかを調べます。World Development Indicators の Harvest Source ID は 2 なので
https://api.worldbank.org/v2/sources/2/concepts
を見ます。すると Country, Series, Time が必要なのがわかります。

Country の一覧は
https://api.worldbank.org/v2/sources/2/country?per_page=500
から取れます。日本(JPN)やアメリカ合衆国(USA)などがあるのがわかります。
Time の一覧は
https://api.worldbank.org/v2/sources/2/time?per_page=500
から取れます。1960年から2019年まであるのがわかります。
Series の一覧は
https://api.worldbank.org/v2/sources/2/series?per_page=500
から取れるのですが、数が多いので GDP が含まれている Series だけに絞ってみます。
https://api.worldbank.org/v2/sources/2/concepts/series/search/gdp
これでもまだ463件ありますが、代表的なものを挙げると
- 国内総生産(GDP)は GDP (current US$) (id : NY.GDP.MKTP.CD)
- 一人当たり GDP は GDP per capita (current US$) (id : NY.GDP.PCAP.CD)
- GDPの成長率は GDP growth (annual %) (id : NY.GDP.MKTP.KD.ZG)
Series の id は Indicator の id として指定でき、
https://api.worldbank.org/v2/sources/2/indicator/NY.GDP.MKTP.CD
で各 Indicator の詳細を見ることができます。
では日本(JPN)の GDP(NY.GDP.MKTP.CD)を見てみましょう。
https://api.worldbank.org/v2/country/jpn/indicator/NY.GDP.MKTP.CD

期間を指定するときは date を使います。
2018年のデータだけ取得するなら
https://api.worldbank.org/v2/country/jpn/indicator/NY.GDP.MKTP.CD?date=2018
2010年〜2018年のように期間を指定するなら : を使います。
https://api.worldbank.org/v2/country/jpn/indicator/NY.GDP.MKTP.CD?date=2010:2018
複数の国のデータを取得するには Country id を ; でつなげます。日本とアメリカ合衆国の GDP を取得するなら
https://api.worldbank.org/v2/country/jpn;usa/indicator/NY.GDP.MKTP.CD?per_page=200
JSON で取得するときは format=json を指定します。
https://api.worldbank.org/v2/country/jpn/indicator/NY.GDP.MKTP.CD?format=json

JSON-stat で取得するときは format=jsonstat を指定します。
https://api.worldbank.org/v2/country/jpn/indicator/NY.GDP.MKTP.CD?format=jsonstat

0 件のコメント:
コメントを投稿