0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

世界銀行のデータ(試しに色々見た)

0
Last updated at Posted at 2023-07-30

世界銀行のAPIでは、以下のような多くの指標についてのデータを提供しています:

  1. 農業と地方開発
  2. 援助の効果
  3. 気候変動
  4. 経済と成長
  5. 教育
  6. エネルギーと鉱業
  7. 環境
  8. 外債

これらの指標は、各国の総人口、国民総所得、エネルギー使用量などのデータを含んでいます。

詳細な指標リストとその説明については、World Bank DataのIndicatorsページをご覧ください。


ということでいくつか試してみた


エネルギーの使用量

以下に、日本、アメリカ、イギリス、中国、インド、ロシアのエネルギー使用量の変化を一つのグラフに表示するコードを示します。エネルギー使用量の指標は "EG.USE.PCAP.KG.OE" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/EG.USE.PCAP.KG.OE?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/EG.USE.PCAP.KG.OE?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/EG.USE.PCAP.KG.OE?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/EG.USE.PCAP.KG.OE?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/EG.USE.PCAP.KG.OE?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/EG.USE.PCAP.KG.OE?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Energy use (kg of oil equivalent per capita)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアのエネルギー使用量の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Energy use (kg of oil equivalent per capita)' が表示されます。


CO2排出量

以下に、日本、アメリカ、イギリス、中国、インド、ロシアのCO2排出量の変化を一つのグラフに表示するコードを示します。CO2排出量の指標は "EN.ATM.CO2E.PC" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/EN.ATM.CO2E.PC?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/EN.ATM.CO2E.PC?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/EN.ATM.CO2E.PC?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/EN.ATM.CO2E.PC?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/EN.ATM.CO2E.PC?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/EN.ATM.CO2E.PC?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('CO2 emissions (metric tons per capita)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアのCO2排出量の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'CO2 emissions (metric tons per capita)' が表示されます。


交通事故による死亡率

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの交通事故による死亡率の変化を一つのグラフに表示するコードを示します。交通事故による死亡率の指標は "SH.STA.TRAF.P5" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/SH.STA.TRAF.P5?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/SH.STA.TRAF.P5?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/SH.STA.TRAF.P5?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/SH.STA.TRAF.P5?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/SH.STA.TRAF.P5?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/SH.STA.TRAF.P5?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Road traffic deaths (per 100,000 people)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの交通事故による死亡率の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Road traffic deaths (per 100,000 people)' が表示されます。


人口の変化

このグラフの縦軸は人口を表しており、その単位は「人」です。ただし、人口の数値は非常に大きいため、通常は千人、百万人、十億人などの単位で表示されます。例えば、1.0e+9は十億人を意味します。

したがって、縦軸のラベルを「人口(十億人)」とします。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/SP.POP.TOTL?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/SP.POP.TOTL?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/SP.POP.TOTL?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/SP.POP.TOTL?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/SP.POP.TOTL?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/SP.POP.TOTL?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Population (Billion)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの人口の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Population (Billion)' が表示されます。


GDP

以下に、日本、アメリカ、イギリス、中国、インド、ロシアのGDPの変化を一つのグラフに表示し、縦軸にラベルを追加するコードを示します。GDPの指標は "NY.GDP.MKTP.CD" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/NY.GDP.MKTP.CD?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/NY.GDP.MKTP.CD?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/NY.GDP.MKTP.CD?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/NY.GDP.MKTP.CD?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/NY.GDP.MKTP.CD?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/NY.GDP.MKTP.CD?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('GDP (current US$)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアのGDPの時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'GDP (current US$)' が表示されます。


銀行の自己資本比率

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの「Bank capital to assets ratio」の変化を一つのグラフに表示するコードを示します。この指標のIDは "FB.BNK.CAPA.ZS" です。

※日本はデータなし

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/FB.BNK.CAPA.ZS?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/FB.BNK.CAPA.ZS?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/FB.BNK.CAPA.ZS?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/FB.BNK.CAPA.ZS?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/FB.BNK.CAPA.ZS?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/FB.BNK.CAPA.ZS?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Bank capital to assets ratio (%)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの「Bank capital to assets ratio」の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Bank capital to assets ratio (%)' が表示されます。


電気へのアクセス(人口比)

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの「電気へのアクセス(人口比)」の変化を一つのグラフに表示するコードを示します。この指標のIDは "EG.ELC.ACCS.ZS" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/EG.ELC.ACCS.ZS?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/EG.ELC.ACCS.ZS?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/EG.ELC.ACCS.ZS?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/EG.ELC.ACCS.ZS?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/EG.ELC.ACCS.ZS?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/EG.ELC.ACCS.ZS?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Access to electricity (% of population)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの「電気へのアクセス(人口比)」の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Access to electricity (% of population)' が表示されます。


0〜14歳の人口(総人口の%)

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの0〜14歳の人口(総人口の%)の変化を一つのグラフに表示するコードを示します。0〜14歳の人口(総人口の%)の指標は "SP.POP.0014.TO.ZS" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/SP.POP.0014.TO.ZS?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/SP.POP.0014.TO.ZS?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/SP.POP.0014.TO.ZS?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/SP.POP.0014.TO.ZS?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/SP.POP.0014.TO.ZS?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/SP.POP.0014.TO.ZS?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Population ages 0-14 (% of total population)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの0〜14歳の人口(総人口の%)の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Population ages 0-14 (% of total population)' が表示されます。


特許出願、居住者

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの「特許出願、居住者」の変化を一つのグラフに表示するコードを示します。この指標のIDは "IP.PAT.RESD" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/IP.PAT.RESD?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/IP.PAT.RESD?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/IP.PAT.RESD?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/IP.PAT.RESD?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/IP.PAT.RESD?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/IP.PAT.RESD?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Patent applications, residents')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの「特許出願、居住者」の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Patent applications, residents' が表示されます。


森林面積(国土に占める割合)

以下に、日本、アメリカ、イギリス、中国、インド、ロシアの「森林面積(国土に占める割合)」の変化を一つのグラフに表示するコードを示します。この指標のIDは "AG.LND.FRST.ZS" です。

import requests
import pandas as pd
import matplotlib.pyplot as plt

# APIのURL
url_jp = "http://api.worldbank.org/v2/country/JP/indicator/AG.LND.FRST.ZS?format=json"
url_us = "http://api.worldbank.org/v2/country/US/indicator/AG.LND.FRST.ZS?format=json"
url_gb = "http://api.worldbank.org/v2/country/GB/indicator/AG.LND.FRST.ZS?format=json"
url_cn = "http://api.worldbank.org/v2/country/CN/indicator/AG.LND.FRST.ZS?format=json"
url_in = "http://api.worldbank.org/v2/country/IN/indicator/AG.LND.FRST.ZS?format=json"
url_ru = "http://api.worldbank.org/v2/country/RU/indicator/AG.LND.FRST.ZS?format=json"

# APIからデータを取得
response_jp = requests.get(url_jp)
data_jp = response_jp.json()
response_us = requests.get(url_us)
data_us = response_us.json()
response_gb = requests.get(url_gb)
data_gb = response_gb.json()
response_cn = requests.get(url_cn)
data_cn = response_cn.json()
response_in = requests.get(url_in)
data_in = response_in.json()
response_ru = requests.get(url_ru)
data_ru = response_ru.json()

# データをデータフレームに変換
df_jp = pd.json_normalize(data_jp[1])
df_us = pd.json_normalize(data_us[1])
df_gb = pd.json_normalize(data_gb[1])
df_cn = pd.json_normalize(data_cn[1])
df_in = pd.json_normalize(data_in[1])
df_ru = pd.json_normalize(data_ru[1])

# 'date'列をdatetime型に変換
df_jp['date'] = pd.to_datetime(df_jp['date'])
df_us['date'] = pd.to_datetime(df_us['date'])
df_gb['date'] = pd.to_datetime(df_gb['date'])
df_cn['date'] = pd.to_datetime(df_cn['date'])
df_in['date'] = pd.to_datetime(df_in['date'])
df_ru['date'] = pd.to_datetime(df_ru['date'])

# グラフを表示
plt.figure(figsize=(10, 6))
plt.plot(df_jp['date'], df_jp['value'], label='Japan')
plt.plot(df_us['date'], df_us['value'], label='USA')
plt.plot(df_gb['date'], df_gb['value'], label='UK')
plt.plot(df_cn['date'], df_cn['value'], label='China')
plt.plot(df_in['date'], df_in['value'], label='India')
plt.plot(df_ru['date'], df_ru['value'], label='Russia')
plt.legend()

# 縦軸のラベルを追加
plt.ylabel('Forest area (% of land area)')

plt.show()

このコードは、日本、アメリカ、イギリス、中国、インド、ロシアの「森林面積(国土に占める割合)」の時間経過による変化を一つのグラフで表示します。また、縦軸のラベルには 'Forest area (% of land area)' が表示されます。


今後は、もっと多くの国を加えて見てみたい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?