This project allows for the analysis of trade data as reported by the United Nations and available through UN Comtrade. Additional data was added using the SPARQL endpoint of Wikidata. After aggregation of the data, you can then explore using a locally hosted Streamlit dashboard.
Note
After downloading this repository as is, a version of the project can be run immediately. However, there is no direct connection to UN Comtrade, as this would violate their use and re-dissemination policy.
- Python 3.12
- packages within requirements.txt
- locally deployed Apache Jena Fuseki server (app.py is querying towards
localhost:3030) - UN Comtrade data
This project contains python scripts, a .csv file with some example data from UN comtrade and an empty .ttl file. They are structured within this repository as follows:
- dashboard
- app.py #streamlit dashboard
- data
- country_ontology.py #ontology for RDF graph
- countrydata.ttl #empty turtle file to store data from main.py
- main.py #script to aggregate data from wikidata and .csv to countrydata.ttl
- plasticstraw.py #script to purge countrydata.ttl
- sircalcalot.py #script to enhance countrydata.ttl with trade balance calculations
- uncomtrade.csv #data downloaded from UN comtrade for the years 2014-2023
- wikidata_queries.py #SPARQL queries for wikidata
To be able to start the dashboard you need to execute the following steps:
- get the UN Comtrade data and save it into .csv OR use data from this repo
runmain.pyrunsircalcalot.py- install1 and run2 local Fuseki server
- upload countrydata_calculated.ttl3 to Fuseki as countrydata_calculated4
runapp.py
Streamlit then deploys the dashboard to http://localhost:8501/ and is ready for exploration.
Footnotes
-
check Apache Jena Fuseki Download here or download using
homebrew. ↩ -
check Fuseki Quickstart or use homebrew via terminal command (macOS)
/opt/homebrew/opt/fuseki/bin/fuseki-server↩ -
will be generated when executing sircalcalot.py ↩
-
app.py is querying
http://localhost:3030/countrydata_calculated/query↩
