#概要
world bankは国際の財務データ等を取得できるのだが、なかなか視覚化が難しい。まあ、excelだと時間がかかるのでなんとかしようという話
#api
日本の総務省なんかはまだ、excelだったりするんだが、さすがアメリカweb apiをサポートしている。
だもんで、これを使うつもりなんだが、まだインフラを決めきれていない
pythonのラッパーがあったので、これとjuputerの利用ということにしようかと思っているのだが
microsoftのpower biというのもあるらしい。でも有料だしなあ・・
node周辺もあるんだろうけど、まだ検索が足りないですかなあ
#wbdata
どうも、ググるとpythonのwbdataというのがよさそうである。
pip install wbdata
でインストールしましょう
ちょっと動かすとエラーがでるので
windows環境の場合
set PYTHONIOENCODING=cp932:xmlcharrefreplace
というおまじないを実行してから
pythonでインタープリターへ
import wbdata
wbdata.api.get_source()
とすると
11 Africa Development Indicators
36 Statistical Capacity Indicators
31 Country Policy and Institutional Assessment
41 Country Partnership Strategy for India (FY2013 - 17)
1 Doing Business
30 Exporter Dynamics Database – Indicators at Country-Year Level
12 Education Statistics
こんな感じである。このsourceというのは情報源でいろんな分類がある
私はno2のWorld Development Indicatorsがほしいのだが、それ以外にも上のような山のようなデータがアクセスできる。
#GDPのデータ
GDPに関するデータを調べると
wbdata.api.search_indicators('GDP',source=2)
で下みたいなデータを参照するということである。
GC.XPN.TOTL.GD.ZS Expense (% of GDP)
GC.TAX.TOTL.GD.ZS Tax revenue (% of GDP)
GC.REV.XGRT.GD.ZS Revenue, excluding grants (% of GDP)
GC.NLD.TOTL.GD.ZS Net lending (+) / net borrowing (-) (% of GDP)
GC.NFN.TOTL.GD.ZS Net investment in nonfinancial assets (% of GDP)
GC.LBL.TOTL.GD.ZS Net incurrence of liabilities, total (% of GDP)
GC.DOD.TOTL.GD.ZS Central government debt, total (% of GDP)
GC.AST.TOTL.GD.ZS Net acquisition of financial assets (% of GDP)
GB.XPD.RSDV.GD.ZS Research and development expenditure (% of GDP)
FS.AST.PRVT.GD.ZS Domestic credit to private sector (% of GDP)
FS.AST.DOMS.GD.ZS Domestic credit provided by financial sector (% of GDP)
FS.AST.DOMO.GD.ZS Claims on other sectors of the domestic economy (% of GDP)
FS.AST.CGOV.GD.ZS Claims on central government, etc. (% GDP)
FM.LBL.BMNY.GD.ZS Broad money (% of GDP)
#実際にデータを取得
d=wbdata.api.get_data('NY.GDP.MKTP.CD',country=('JPN','US'))
で、データを取得できる。
ここでは、国に日本とアメリカを設定したが、なにも指定しないと、全世界の
1960年からのデータを持ってくる。まあ、データがちゃんとあるのはOECD諸国ぐらいだが、このデータをpandaに食わせて、分析するというわけである。
#結論
というわけで
以下のソースで
# coding:utf-8
import wbdata
import pandas
import matplotlib.pyplot as plt
cc = ["JPN","US","CHN"]
ic = {"NY.GDP.MKTP.CD":"GDP"}
df = wbdata.api.get_dataframe(ic,country=cc,convert_date=False)
dfu = df.unstack(level=0)
dfu.plot();
plt.legend(loc='best');
plt.show()
すんばらしい!