2018年12月12日水曜日

Jupyterとpandasdmxを使用して、OECDの空港インフラ維持費データを取得する

Jupyterとpandasdmxを使用して、OECDの空港インフラ維持費(Airport infrastructure maintenance)データを取得してグラフ表示するには、以下のコードを実行します。

〇出力グラフ


〇コード
from pandasdmx import Request
import matplotlib.pyplot as plt

oecd = Request('OECD')
countries="POL+HRV+FIN"
data_response = oecd.data(resource_id='ITF_INV-MTN_DATA', key=countries + ".I-MTN-AIR.EUR/all?startTime=1995&endTime=2016")
oecd_data = data_response.data

df = data_response.write(oecd_data.series, parse_time=True)
df = df.unstack(level=0).to_frame()
df.columns=['Euro']
df = df.reset_index()
df = df[["COUNTRY", "TIME_PERIOD", "Euro"]]
df.set_index(["COUNTRY", "TIME_PERIOD"], inplace=True)
ax = df.unstack(level=0).plot()
plt.xticks(rotation=90)
plt.legend(loc='best')
plt.show()

〇元データ
Transport infrastructure investment and maintenance spending
https://stats.oecd.org/Index.aspx?DataSetCode=ITF_INV-MTN_DATA


○関連情報
・Pandasdmxに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿