 |
Show GDP / capita from CVS file using WorldBank data
Source code name: "canvas2D_chartBar_cvs.py"
Programming language: Python
Topic: Plots/2D
DMelt Version 1. Last modified: 03/03/2021. License: Pro
https://datamelt.org/code/cache/canvas2D_chartBar_cvs_286.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Download CVS file from https://data.worldbank.org/indicator/NY.GDP.PCAP.CD
# The file should have the name ny.gdp.pcap.cd_Indicator_en_csv_v2.csv
from jhplot.io.csv import *
from java.io import *
from jhplot import *
import urllib
urllib.urlretrieve ("https://datamelt.org/examples/data/ny.gdp.pcap.cd_Indicator_en_csv_v2.csv", "tmp.csv")
dict={}
reader =CSVReader(FileReader("tmp.csv"));
while True:
nextLine = reader.readNext()
if nextLine== None: break
xlen=len(nextLine)
if xlen<50: continue
dict[nextLine[0]]=nextLine[xlen-2] # key: country, vaue=DGP
c1 = HChart("2013",800,400)
#c1.setGTitle("2013 Gross domestic product per capita")
c1.visible()
c1.setChartBar()
c1.setNameY("current US $")
c1.setNameX("")
c1.setName("2013 Gross domestic product per capita")
name1="Data Source: World Development Indicators"
name="Russia"; c1.valueBar(float(dict[name]) ,name,name1)
name="Poland"; c1.valueBar(float(dict[name]) ,name,name1)
name="Romania"; c1.valueBar(float(dict[name]) ,name,name1)
name="Bulgaria"; c1.valueBar(float(dict[name]) ,name,name1)
name="Belarus"; c1.valueBar(float(dict[name]) ,name,name1)
name="Ukraine"; c1.valueBar(float(dict[name]) ,name,name1)
c1.update()
You see the box below because you did not login.