In [13]: wbdata.get_source() 11 Africa Development Indicators 36 Statistical Capacity Indicators 31 Country Policy and Institutional Assessment (CPIA) 41 Country Partnership Strategy for India 26 Corporate Scorecard 1 Doing Business ... 43 Wealth accounting 2 World Development Indicators 3 Worldwide Governance Indicators
In [14]: wbdata.get_country() ... UZB Uzbekistan VCT St. Vincent and the Grenadines VEN Venezuela, RB VGB British Virgin Islands VIR Virgin Islands (U.S.) VNM Vietnam VUT Vanuatu WLD World WSM Samoa XKX Kosovo XZN Sub-Saharan Africa excluding South Africa and Nigeria YEM Yemen, Rep. ZAF South Africa ZMB Zambia ZWE Zimbabwe
In [20]: topics = wbdata.get_topic(display = False)
In [21]: type(topics) Out[21]: list
In [22]: type(topics[0]) Out[22]: dict
In [23]: print topics[0] {u'id': u'1', u'value': u'Agriculture & Rural Development', u'sourceNote': u"For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment. But depletion and degradation of land and water pose serious challenges to producing enough food and other agricultural products to sustain livelihoods here and meet the needs of urban populations. Data presented here include measures of agricultural inputs, outputs, and productivity compiled by the UN's Food and Agriculture Organization."}
接下来,我们希望查询人均 GDP 的相关情况。我们知道人均 GDP 的英文写法是 GDP per capita(如果你不知道,那么你应该补补课了),我们试着在世行的数据库里检索和人均 GDP 相关的指标。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
In [29]: wbdata.search_indicators('GDP per capita') GDPPCKD GDP per Capita, constant US$, millions GDPPCKN Real GDP per Capita (real local currency units, various base years) NV.AGR.PCAP.KD.ZG Real agricultural GDP per capita growth rate (%) NY.GDP.PCAP.CD GDP per capita (current US$) NY.GDP.PCAP.KD GDP per capita (constant 2000 US$) NY.GDP.PCAP.KD.ZG GDP per capita growth (annual %) NY.GDP.PCAP.KN GDP per capita (constant LCU) NY.GDP.PCAP.PP.CD GDP per capita, PPP (current international $) NY.GDP.PCAP.PP.KD GDP per capita, PPP (constant 2005 international $) NY.GDP.PCAP.PP.KD.ZG GDP per capita, PPP annual growth (%) SE.XPD.PRIM.PC.ZS Expenditure per student, primary (% of GDP per capita) SE.XPD.SECO.PC.ZS Expenditure per student, secondary (% of GDP per capita) SE.XPD.TERT.PC.ZS Expenditure per student, tertiary (% of GDP per capita)
我们注意到,其中有一个名为 NY.GDP.PCAP.PP.CD 的指标。它的含义是:人均 GDP 占比按实际购买力折算之后以美元计价的值。听起来是一个高大上的指标,不是吗?我们试着以它为例,获取所需的数据。
wbdata 提供了 get_data 函数,用以获取数据。
1 2 3 4 5 6 7 8 9 10
In [50]: res = wbdata.get_data('NY.GDP.PCAP.PP.CD', country = ['CHN', 'USA'])
In [51]: type(res) Out[51]: list
In [52]: type(res[0]) Out[52]: dict
In [53]: print res[0] {u'date': u'2016', u'country': {u'id': u'CN', u'value': u'China'}, u'indicator': {u'id': u'NY.GDP.PCAP.PP.CD', u'value': u'GDP per capita, PPP (current international $)'}, u'decimal': u'1', u'value': None}
In [56]: countries = ['CHN', 'USA'] ...: indicators = {'NY.GDP.PCAP.PP.CD' : 'GDP per capita, PPP (current international $)'} ...: dt = (datetime.datetime(2000, 1, 1), datetime.datetime(2017, 1, 1)) ...: df = wbdata.get_dataframe(indicators, country = countries, convert_date = False, data_date = dt) ...:
In [57]: df Out[57]: GDP per capita, PPP (current international $) country date China 2016 NaN 201514450.174744 201413439.907642 201312367.965864 201211351.062843 201110384.367317 20109333.124882 20098374.432850 20087635.073139 20076863.982229 20065883.719784 20055092.560189 20044455.205330 20033961.274167 20023551.663897 20013226.848680 20002933.315020 United States 2016 NaN 201556115.718426 201454539.665575 201352749.911240 201251433.047090 201149781.800656 201048374.086793 200947001.555350 200848401.427340 200748061.537661 200646437.067117 200544307.920585 200441921.809762 200339677.198348 200238166.037841 200137273.618103 200036449.855116