Starting from previous Google Colab notebook
The following steps will serve as a guideline to read data from WITS database and find mirror statistics:
Load the notebook with commands developed in step 2.2. (click on the link):
https://colab.research.google.com/drive/1B2xiY2xg-VL_tWxJfqNKXAbTuBio2ksJ?usp=sharing
Install the WITS package using the command:
!pip install world_trade_data --upgrade
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting world_trade_data Downloading world_trade_data-0.1.1.tar.gz (11 kB) Preparing metadata (setup.py) ... done ...
Successfully built world_trade_data Installing collected packages: xmltodict, world_trade_data Successfully installed world_trade_data-0.1.1 xmltodict-0.13.0
Enable the use of the WITS python package with the command:
import world_trade_data as wits
Obtain a table with data from several countries (iso3code is important data):
df_countries = wits.get_countries()
df_countries
5. Find the rows with information for specific countries using the command:
df_countries[df_countries['name'] == 'Rwanda']
6. Get a table with the indicators available in the database:
df_indicators = wits.get_indicators()
5. Get the definition of all indicators:
df_indicators['definition'].to_dict()
{'CNTRY-GRWTH': 'Annual percentage growth rate of the country’s trade value (export or import), by sector, at market prices in current U.S. dollars.',
'HH-MKT-CNCNTRTN-NDX': 'Hirschman Herfindahl index is a measure of the dispersion of trade value across an exporter’s partners. A country with trade (export or import) that is concentrated in a very few markets will have an index value close to 1. Similarly, a country with a perfectly diversified trade portfolio will have an index close to zero.',
'MPRT-PRDCT-SHR': 'The share of total merchandise trade (export or import) accounted for by the product in a given year.',
'MPRT-PRTNR-SHR': 'The share of total merchandise trade (export or import) accounted for by the partner in a given year.',
'MPRT-SHR-TTL-PRDCT': 'Share in Total Products (%)',
'MPRT-TRD-VL': 'Total Import/Export Value in thousands of US Dollars current value.',
'NDX-XPRT-MKT-PNRTTN': 'It is calculated as the number of countries to which the reporter exports a particular product divided by the number of countries that report importing the product that year.',
'NMBR-MPRT-HS6-PRDCT': 'Total number of products imported by a country at the Harmonized System (HS) six digit level in any given year.', 'NMBR-MPRT-PRTNR': 'Number of countries from which a particular country imports data in any given year.',
'NMBR-PRDCT-MPRTD': 'Total number of products imported by a country at the Harmonized System (HS) six digit level in any given year.',
'NMBR-PRDCT-XPRTD': 'Total number of products exported by a country at the Harmonized System (HS) six digit level in any given year.',
'NMBR-XPRT-HS6-PRDCT': 'Total number of products exported by a country at the Harmonized System 1998 (HS 2) six digit level in any given year.',
'NMBR-XPRT-PRTNR': 'Number of countries to whom a particular country exports data in any given year.',
'RCA': 'Measures of revealed comparative advantage (RCA) have been used to help assess a country’s export potential. The RCA indicates whether a country is in the process of extending the products in which it has a trade potential, as opposed to situations in which the number of products that can be competitively exported is static. It can also provide useful information about potential trade prospects with new partners.',
'TRD-CMPLMNTRTY-NDX': 'The trade complementarity (TC) index can provide useful information on prospects for intraregional trade in that it shows how well the structures of a country’s imports and exports match. It also has the attraction that its values for countries considering the formation of a regional trade agreement can be compared with others that have formed or tried to form similar arrangements.',
'WRLD-GRWTH': 'Annual percentage growth rate of the world’s trade value (export or import), by sector, at market prices in current U.S. dollars.',
'XPRT-PRDCT-SHR': 'The share of total merchandise trade (export or import) accounted for by the product in a given year.',
'XPRT-PRTNR-SHR': 'The share of total merchandise trade (export or import) accounted for by the partner in a given year.',
'XPRT-SHR-TTL-PRDCT': 'Share in Total Products (%)',
'XPRT-TRD-VL': 'Total Import/Export Value in thousands of US Dollars current value.'}
6. Obtain a detailed table with importation values for the country Rwanda (iso3code = 'rwa') from the country Zambia (iso3code = 'zmb'):
wits.get_indicator('MPRT-TRD-VL', partner='zmb', reporter='rwa', year='2010')
7. Obtain the total importation from Rwanda:
rwa_imports_2010['Value'].sum()
16174.79258731425
8. Obtain a detailed table with exportation values for the country Zambia (iso3code = 'zmb') from the country Rwanda (iso3code = 'rwa'):
wits.get_indicator('XPRT-TRD-VL', partner='rwa', reporter='zmb', year='2010')
9. Obtain the total of exportation from Zambia:
zmb_exports_2010['Value'].sum()
12147.604
10. Compute the percentage of the difference between the two previous measures:
difference = total_rwa_from_zmb - total_zmb_to_rwa
perc_difference = (difference/total_zmb_to_rwa)*100
33.152122733950264
11. The Python code with all the steps is summarized in this Google Colab (click on the link):
https://colab.research.google.com/drive/1S24nLFMr_yeo4VmXlpq8WKM7qcNLL1ZI?usp=sharing