wbdata library reference

Wbdata provides a set of functions that are used to interface with the World Bank’s databases. For any function involving pandas capabilities, pandas must (obviously) be installed.

Convenience Functions

wbdata.search_indicators(query, source=None, topic=None, display=None)

Search indicators for a certain term. Very simple. Only one of source or topic can be specified. In interactive mode, will return None and print ids and names unless suppress_printing is True.

Query:the term to match against indicator names
Source:if present, id of desired source
Topic:if present, id of desired topic
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:a list of dictionaries representing indicators if display is False
wbdata.search_countries(query, incomelevel=None, lendingtype=None, display=None)

Search countries by name. Very simple search.

Query:the string to match against country names
Incomelevel:if present, search only the matching incomelevel
Lendingtype:if present, search only the matching lendingtype
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:a list of dictionaries representing countries if display is False
wbdata.get_dataframe(indicators, country=u'all', data_date=None, convert_date=False, keep_levels=False)
Convenience function to download a set of indicators and merge them into a
pandas DataFrame. The index will be the same as if calls were made to get_data separately.
Indicators:An dictionary where the keys are desired indicators and the values are the desired column names
Country:a country code, sequence of country codes, or “all” (default)
Data_date:the desired date as a datetime object or a 2-sequence with start and end dates
Convert_date:if True, convert date field to a datetime.datetime object.
Keep_levels:if True and pandas is True, don’t reduce the number of index levels returned if only getting one date or country
Returns:a pandas dataframe
wbdata.get_panel(indicators, country=u'all', data_date=None, convert_date=False, items=u'indicators', major_axis=u'dates')
Convenience function to download a set of indicators and merge them into a
pandas Panel.
Indicators:An dictionary where the keys are desired indicators and the values are the desired column names
Country:a country code, sequence of country codes, or “all” (default)
Data_date:a 2-sequence with start and end dates
Convert_date:if True, convert date field to a datetime.datetime object.
Items:which values to use as the Panel items. One of “indicators”, “countries”, “dates”
Major_axis:which values to use as major axis for each item. One of “indicators”, “countries”, “dates”
Returns:a pandas panel

Finding the data you want

wbdata.get_source(source_id=None, display=None)

Retrieve information on a source

Source_id:a source id or sequence thereof. None returns all sources
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:if display is False, a dictionary describing a source
wbdata.get_topic(topic_id=None, display=None)

Retrieve information on a topic

Topic_id:a topic id or sequence thereof. None returns all topics
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:if display is False, a dictionary describing an income level aggregate
wbdata.get_lendingtype(type_id=None, display=None)

Retrieve information on an income level aggregate

Level_id:lending type id or sequence thereof. None returns all lending type aggregates
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:if display is False, a dictionary describing an lending type aggregate
wbdata.get_incomelevel(level_id=None, display=None)

Retrieve information on an income level aggregate

Level_id:a level id or sequence thereof. None returns all income level aggregates
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:if display is False a dictionary describing an income level aggregate
wbdata.get_country(country_id=None, incomelevel=None, lendingtype=None, display=None)

Retrieve information on a country or regional aggregate. Can specify either country_id, or the aggregates, but not both

Country_id:a country id or sequence thereof. None returns all countries and aggregates.
Incomelevel:desired incomelevel id or ids.
Lendingtype:desired lendingtype id or ids.
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise.
Returns:if display is False, a dictionary describing an lending type aggregate.
wbdata.get_indicator(indicator=None, source=None, topic=None, display=None)

Retrieve information about an indicator or indicators. Only one of indicator, source, and topic can be specified. Specifying none of the three will return all indicators.

Indicator:an indicator code or sequence thereof
Source:a source id or sequence thereof
Topic:a topic id or sequence thereof
Display:if True,print ids and names instead of returning results. Defaults to True if in interactive prompt, or False otherwise
Returns:if display is False, a list of dictionary objects representing indicators

Retrieving your data

wbdata.get_data(indicator, country=u'all', data_date=None, convert_date=False, pandas=False, column_name=u'value', keep_levels=False)

Retrieve indicators for given countries and years

Indicator:the desired indicator code
Country:a country code, sequence of country codes, or “all” (default)
Date:the desired date as a datetime object or a 2-tuple with start and end dates
Convert_date:if True, convert date field to a datetime.datetime object.
Pandas:if True, return results as a pandas Series. The index will be the date of the data if only one country is specified, the countries if only one date is specified, or a multi-index of country and date otherwise.
Column_name:the desired name for the pandas column
Keep_levels:if True and pandas is True, don’t reduce the number of index levels returned if only getting one date or country
Returns:list of dictionaries or pandas Series