Skip to content

Examples on how to use Statistics Norways external API in Jupyter notebooks. Examples are both in Norwegian and in English

License

Notifications You must be signed in to change notification settings

janbrus/ssb-api-python-examples

Repository files navigation

ssb-api-python-examples

Norsk - for English see below

Hvordan bruke Python mot SSBs API-er, vist med Jupyter notebooks

Statistisk sentralbyrå (SSB) tilbyr tre API-er for å hente ut og integrere SSBs data med egne systemer. API-ene er åpne og krever ikke registrering:

  • API for å poste spørringer i JSON mot alle Statistikkbankens 7000 tabeller (PxWebApi): Dette API-et lar deg sende spørringer i JSON-format mot alle tabeller i Statistikkbankens.
  • API med ferdige datasett: Dette enkle API-et gir deg tilgang til 210 oppdaterte datasett med fast URL, hentet fra de mest brukte tabellene i Statistikkbanken.
  • REST API for statistiske klassifikasjoner og kodelister: Dette API-et gir deg tilgang til statistiske klassifikasjoner og kodelister (Klass).

Alle eksempler bruker Python Pandas.

API med ferdige datasett - CSV

  • Varehandel - veldig enkelt eksempel med lite datasett.
  • Konjunkturtendensene - Importerer et ferdig CSV datasett til Pandas, med 10 oppdaterte økonomiske prognoser. Viser enkle diagram med Pandas plot og Plotly Express.

JSON-stat eksempler for å poste spørringer mot PxWebApi

  • Laks - Post spørring og få Pandas dataframe i retur
  • JsonStatToPandas - To funksjoner for å poste JSON spørring og få Pandas dataframe i retur
  • komm-nr-id - Hvordan vise både kommunenummer/-kode og kommunenavn i en dataframe, dvs. vise kode og tekst i JSON-stat
  • Kombiner to tabeller - Spørre mot to ulike Statstikkbank-tabeller og vise resultatet i en figur med Pandas pivot og Matplotlib.
  • Konkurs-datokonv - Funksjon for å konvertere Tid fra kategori til datoformat. Viser forskjellen i to figurer med ukentlige konkurser.
  • Nasjonalregnskap-datokonvertering - Viser samme spørring mot tabeller med ulik frakvense, her BNP-endring i månedlig, kvartalsvis og årlig nasjonalregnskap. Viser dateconv() som konverterer fra kategori til dataoformat og setter Pandas Period.
  • text-code - Få Kode og Tekst i JSON-stat - eksempel med HS-varekoder i månedlig Utenrikshandel

Klassifikasjoner og kodelister (Klass)

  • Klasskommune - Standard for kommuneinndeling til Pandas.
  • KOSTRA-koder - KOSTRA koder for regnskapsarter og -funksjoner. Hvordan hente og filtrere KOSTRA arter og funksjoner med definisjoner via Klass API (KOSTRA - Municipality-State-Reporting)

Lenker for mer informasjon:

R-bruker? Bruk i stedet R-pakken PxWebApiData og se denne Introduksjonen

English

Jupyter notebooks on how to use Python to access Statstics Norways APIs

Statistics Norway offers three APIs that allow you to retrieve and integrate SSB's data with your own systems. These APIs are open and do not require registration. Here is a brief overview of the three APIs:

  1. API for posting queries in JSON to all of Statbank Norway's 7000 tables (PxWebApi): This API allows you to send queries in JSON format to all of Statistikkbanken's tables.
  2. API for ready-made datasets: This API provides access to 210 datasets with fixed URLs, extracted from the most frequently used tables in the Statbank.
  3. REST API for statistical classifications and code lists: This API provides access to statistical classifications and code lists.

Examples using CSV from the API for Readymade datasets

  • Basic a very basic example on Index of retail sales.
  • Economic trends Import a readymade CSV dataset, Main Economic Forecasts, to Pandas. Shows basic plots using Pandas plot and Plotly Express.

Examples using http POST to query PxWebApi

All examples are using JSON-stat output and the library pyjstat

  • basic - a basic example on using http POST to query PxWebApi.
  • jsonstatToPandas_function - General function to read JSON-stat to Pandas dataframes
  • two-tables-one-chart - http POST example, combines two datasets from two Statbank tables using Pandas pivot, and plot them using Matplotlib.
  • bankrupties - shows the use of a general function for converting the time variable from category to date, and the difference of the two in two plots. The table used is on weekly bankruptcies.
  • gdp-dateconv - shows posting of the same query for GDP changes to tables with different frequency, and the use of the function dateconv() which converts from Categories to dateformat and set a Pandas PeriodIndex.
  • text-code - shows how to get both text and code from JSON-stat. Example using HS-code from monthly Foreign trade by country.

Example on Statistics Norway's Statistical Classifications and Codelists API

Using R ? Try our R-package PxWebApiData and see Introduction

About

Examples on how to use Statistics Norways external API in Jupyter notebooks. Examples are both in Norwegian and in English

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages