2018年11月26日月曜日

Jupyterとpandasdmxを使用して、OECDの農耕地面積データを取得する

Jupyterとpandasdmxを使用して、OECDの農耕地面積(千ヘクタール)データを取得してグラフ表示するには、以下のコードを実行します。

〇出力グラフ


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

oecd = Request('OECD')
countries="JPN+USA+AUS"
data_response = oecd.data(resource_id='AEI_OTHER', key=countries + ".TOTAGR_LAND/all?startTime=1985&endTime=2017")
oecd_data = data_response.data

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

〇元データ
Agri-Environmental other indicators
https://stats.oecd.org/Index.aspx?DataSetCode=AEI_OTHER


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

0 件のコメント:

コメントを投稿