def test_parse_dataset():
    f = os.path.join(jsonstat._examples_dir, "www.json-stat.org",
                     "canada.json")
    dataset = jsonstat.from_file(f)
    assert dataset is not None
    assert isinstance(dataset, jsonstat.JsonStatDataSet)
    assert 120 == len(dataset)
Exemple #2
0
def test_parsing_json_stat_org_files():
    for f in os.listdir(fixture_jsonstat_org_dir):
        jsonstat_file = join(fixture_jsonstat_org_dir, f)
        if isfile(jsonstat_file) and jsonstat_file.endswith(".json"):
            # print("parsing {}".format(jsonstat_file))
            ret = jsonstat.from_file(jsonstat_file)
            msg = "parsing {}".format(jsonstat_file)
            assert ret is not None, msg
 def test_parsing_json_stat_org_files(self):
     for f in os.listdir(self.fixture_jsonstat_org_dir):
         jsonstat_file = join(self.fixture_jsonstat_org_dir, f)
         if isfile(jsonstat_file) and jsonstat_file.endswith(".json"):
             # print("parsing {}".format(jsonstat_file))
             ret = jsonstat.from_file(jsonstat_file)
             msg = "parsing {}".format(jsonstat_file)
             self.assertIsNotNone(ret, msg)
def test_parsing_json_stat_org_files():
    example_jsonstat_org_dir = os.path.join(jsonstat._examples_dir,
                                            "www.json-stat.org")
    for f in os.listdir(example_jsonstat_org_dir):
        jsonstat_file = join(example_jsonstat_org_dir, f)
        if isfile(jsonstat_file) and jsonstat_file.endswith(".json"):
            # print("parsing {}".format(jsonstat_file))
            ret = jsonstat.from_file(jsonstat_file)
            msg = "parsing {}".format(jsonstat_file)
            assert ret is not None, msg
Exemple #5
0
def info(cache_dir, args):
    if len(args) == 0:
        args = ['http://json-stat.org/samples/oecd-canada-col.json']

    d = jsonstat.cache_dir(cache_dir)
    print("downloaded file(s) are stored into '{}'\n".format(d))
    for arg in args:

        if arg.startswith("http"):
            print("download '{}'".format(arg))
            o = jsonstat.from_url(arg)
        else:
            print("reading '{}'".format(arg))
            o = jsonstat.from_file(arg)

        print(o)
        if isinstance(o, jsonstat.JsonStatCollection):
            print("\nfirst dataset:\n")
            print(o.dataset(0))
Exemple #6
0
def info(cache_dir, args):
    if len(args) == 0:
        args = ['http://json-stat.org/samples/oecd-canada-col.json']

    d = jsonstat.cache_dir(cache_dir)
    print("downloaded file(s) are stored into '{}'\n".format(d))
    for arg in args:

        if arg.startswith("http"):
            print("download '{}'".format(arg))
            o = jsonstat.from_url(arg)
        else:
            print("reading '{}'".format(arg))
            o = jsonstat.from_file(arg)

        print(o)
        if isinstance(o, jsonstat.JsonStatCollection):
            print("\nfirst dataset:\n")
            print(o.dataset(0))
def llegir_indicador_world_bank(indicador):
    # Consultem via API la web del Banc Mundial.
    # La funció retorna un Panda DataFrame amb les columnes "ISO3","year","<indicador>"

    filename = os.getcwd() + "/" + indicador + ".jsonstat"
    url = "https://api.worldbank.org/v2/country/all/indicator/" + indicador + "?format=jsonstat"

    if os.path.isfile(filename):
        jstat = jsonstat.from_file(filename)
    else:
        jstat = jsonstat.from_string(jsonstat.download(url, filename))

    df = jstat.dataset(0).to_data_frame(content='id')

    df.drop(columns="series", inplace=True)
    df.rename(columns={"country": "ISO3", "Value": indicador}, inplace=True)

    # Assimilem les dades de 2018 a l'any 2019 a l'espera de la seva publicació
    j = 0
    for i in (df.loc[df.year == '2019']).index:
        df.at[i, indicador] = (df.loc[df.year == '2018', indicador]).values[j]
        j += 1

    return df
 def test_parse_dataset(self):
     f = os.path.join(self.fixture_jsonstat_org_dir, "canada.json")
     dataset = jsonstat.from_file(f)
     self.assertIsNotNone(dataset)
     self.assertIsInstance(dataset, jsonstat.JsonStatDataSet)
     self.assertEqual(120, len(dataset))
@author: P.Jakobsen

From https://jsonstatpy.readthedocs.io/en/latest/notebooks/eurostat.html
"""


from __future__ import print_function
import os
import pandas as pd
import jsonstat

import matplotlib as plt

url_1 = 'http://ec.europa.eu/eurostat/wdds/rest/data/v1.1/json/en/nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'
file_name_1 = "eurostat-environmental-tax.json"

url_1="http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/nama_10_gdp?geo=EU28&precision=1&na_item=B1GQ&unit=CP_MEUR&time=2010&time=2011"
#url_1="http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'"
file_path_1 = "data/"+file_name_1
if os.path.exists(file_path_1):
    print("using already donwloaded file {}".format(file_path_1))
else:
    print("download file")
    jsonstat.download(url_1, file_name_1)
    file_path_1 = file_name_1
collection_1 = jsonstat.from_file(file_path_1)
collection_1

nama_gdp_c_1 = collection_1.dataset('nama_gdp_c')
nama_gdp_c_1