Access to WorldBank DatasourceΒΆ

Create DataStore for WorldBank by passing worldbank at initialization.

In [1]: import pyopendata as pyod

In [2]: store = pyod.DataStore('worldbank')

In [3]: store
Out[3]: WorldBankStore (http://api.worldbank.org)

Get GDP per capita (current US$) data. The result will be a DataFrame which has DatetimeIndex as index, and indicator and conutries as column. The target URL is:

We can read above URL as:

  • Resource ID: NY.GDP.PCAP.CD
In [4]: resource = store.get('NY.GDP.PCAP.CD')

In [5]: resource
Out[5]: WorldBankResource (http://api.worldbank.org/countries/all/indicators/NY.GDP.PCAP.CD?format=json)

In [6]: df = resource.read();

In [7]: df.columns
Out[7]: 
MultiIndex(levels=[[u'GDP per capita (current US$)'], [u'Afghanistan', u'Albania', u'Algeria', u'American Samoa', u'Andean Region', u'Andorra', u'Angola', u'Antigua and Barbuda', u'Arab World', u'Argentina', u'Armenia', u'Aruba', u'Australia', u'Austria', u'Azerbaijan', u'Bahamas, The', u'Bahrain', u'Bangladesh', u'Barbados', u'Belarus', u'Belgium', u'Belize', u'Benin', u'Bermuda', u'Bhutan', u'Bolivia', u'Bosnia and Herzegovina', u'Botswana', u'Brazil', u'Brunei Darussalam', u'Bulgaria', u'Burkina Faso', u'Burundi', u'Cabo Verde', u'Cambodia', u'Cameroon', u'Canada', u'Caribbean small states', u'Cayman Islands', u'Central African Republic', u'Central Europe and the Baltics', u'Chad', u'Channel Islands', u'Chile', u'China', u'Colombia', u'Comoros', u'Congo, Dem. Rep.', u'Congo, Rep.', u'Costa Rica', u'Cote d'Ivoire', u'Croatia', u'Cuba', u'Curacao', u'Cyprus', u'Czech Republic', u'Denmark', u'Djibouti', u'Dominica', u'Dominican Republic', u'East Asia & Pacific (all income levels)', u'East Asia & Pacific (developing only)', u'East Asia and the Pacific (IFC classification)', u'Ecuador', u'Egypt, Arab Rep.', u'El Salvador', u'Equatorial Guinea', u'Eritrea', u'Estonia', u'Ethiopia', u'Euro area', u'Europe & Central Asia (all income levels)', u'Europe & Central Asia (developing only)', u'Europe and Central Asia (IFC classification)', u'European Union', u'Faeroe Islands', u'Fiji', u'Finland', u'Fragile and conflict affected situations', u'France', u'French Polynesia', u'Gabon', u'Gambia, The', u'Georgia', u'Germany', u'Ghana', u'Greece', u'Greenland', u'Grenada', u'Guam', u'Guatemala', u'Guinea', u'Guinea-Bissau', u'Guyana', u'Haiti', u'Heavily indebted poor countries (HIPC)', u'High income', u'High income: OECD', u'High income: nonOECD', u'Honduras', ...]],
           labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, ...]],
           names=[u'indicator', u'country'])

You can access to specific data by slicing column.

In [8]: jp = df['GDP per capita (current US$)']['Japan']

In [9]: jp
Out[9]: 
date
1960-01-01    478.995340
1961-01-01    563.586760
1962-01-01    633.640315
...
2011-01-01    46203.698037
2012-01-01    46548.269637
2013-01-01    38492.088895
Name: Japan, Length: 54