Examples

Examples #

Wbdata library #

Our team added wbdata library, which is a simple Python interface used to find and request information from the World Bank’s various databases. It can be used in scripting field. Here are some short example scripts on how to use it.

# Import World Bank Data package
import wbdata
# Get a dataframe
df = wbdata.get_dataframe({'FP.CPI.TOTL.ZG': 'value'}, country=['USA', 'CHN', 'DEU'])
# The script should always return an object of type pandas.DataFrame.
return df
# Import World Bank Data package
import wbdata
# Get a dataframe
df = wbdata.get_dataframe({'SP.POP.TOTL': 'value'}, country='all')
# The script should always return an object of type pandas.DataFrame.
return df

or

# Import World Bank Data package
import wbdata
# Get a series and convert to dataframe
dataframe = wbdata.get_series('SP.POP.TOTL', country='all', column_name='value').to_frame()
# The script should always return an object of type pandas.DataFrame.
return dataframe

or

# Import pandas
import pandas as pd
# Import World Bank Data package
import wbdata
# Get raw json data
data = wbdata.get_data('SP.POP.TOTL', country='all')
# Select and convert data to dataframe
dataframe = pd.DataFrame(
    [[i["country"]["value"], i["date"], i["value"]] for i in data],
    columns=["country", "date", "value"]
)
# The script should always return an object of type pandas.DataFrame.
return dataframe

UNSDG #

We prepared also simple Python script used to call data for all countries on an individual indicator.

# Import pandas
import pandas as pd
# Import requests package for making requests to external API's
import requests
# Request to external API
response = requests.get('example.com', verify=False)
# Convert response json to DataFrame
dataframe = pd.DataFrame(response.json())
# The script should always return an object of type pandas.DataFrame.
return dataframe