2018年12月1日土曜日

Jupyterとpandasdmxを使用して、OECDの小売業前年同月比データを取得する

Jupyterとpandasdmxを使用して、OECDの小売業(Retrail Trade volume)前年同月比データを取得してグラフ表示するには、以下のコードを実行します。

〇出力グラフ


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

oecd = Request('OECD')
countries="JPN+USA+FRA"
data_response = oecd.data(resource_id='KEI', key="SLRTTO01." + countries + ".GY.M/all?startTime=2017&endTime=2018")
oecd_data = data_response.data

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

〇元データ
Key Short-Term Economic Indicators
https://stats.oecd.org/Index.aspx?DataSetCode=KEI

0 件のコメント:

コメントを投稿