{ "cells": [ { "cell_type": "markdown", "id": "cd2f0c7a", "metadata": {}, "source": [ "
\n", "\n", "# How much will you pay for electricity next year?\n", "\n", "ElCom, the Federal Electricity Commission, collects data on the electricity tariffs for household and companies. This data is published as [Linked Data](https://en.wikipedia.org/wiki/Linked_data). \n", "\n", "In this data story, we will show you how to calculate your electricity bills for next year **using Linked Data.** Mainly, you will see how to extract, process, and interpret with data on electricity tariffs. \n", "\n", "Enjoy the ride!" ] }, { "cell_type": "code", "execution_count": 1, "id": "d2f8138f", "metadata": { "scrolled": false }, "outputs": [], "source": [ "import json\n", "import re\n", "import string\n", "\n", "import branca.colormap as cm\n", "import folium\n", "import mapclassify\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import matplotlib.colors as mcolors\n", "import pandas as pd\n", "\n", "from graphly.api_client import SparqlClient\n", "\n", "%matplotlib inline\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 2, "id": "f80432ff", "metadata": { "scrolled": false }, "outputs": [], "source": [ "# Uncomment to install dependencies in Colab environment\n", "#!pip install mapclassify\n", "#!pip install git+https://github.com/zazuko/graphly.git" ] }, { "cell_type": "markdown", "id": "a09e1065", "metadata": {}, "source": [ "### SPARQL endpoints\n", "\n", "#### For electricity tariffs\n", "Data on all electricity tariffs is published as Linked Data. It can be accessed with [SPARQL queries](https://www.w3.org/TR/rdf-sparql-query/). \n", "You can send queries using HTTP requests. The API endpoint is **[https://lindas.admin.ch/query/](https://int.lindas.admin.ch/query).** \n", "\n", "#### For geodata\n", "Different municipalities may have different tariffs. To understand their location, we will work with \n", "Swiss geodata. It is published as Linked Data. It can be accessed using API endpoint under **[https://geo.ld.admin.ch/query](https://geo.ld.admin.ch/query).** " ] }, { "cell_type": "code", "execution_count": 3, "id": "55a2bac1", "metadata": { "scrolled": false }, "outputs": [], "source": [ "sparql = SparqlClient(\"https://lindas.admin.ch/query\")\n", "geosparql = SparqlClient(\"https://geo.ld.admin.ch/query\")\n", "\n", "sparql.add_prefixes({\n", " \"schema\": \"\n", " | municipality_id | \n", "increase | \n", "fixcosts_old | \n", "fixcosts_new | \n", "price_old | \n", "price_new | \n", "elcom_details | \n", "
---|---|---|---|---|---|---|---|
918 | \n", "https://ld.admin.ch/municipality/4073 | \n", "284.39150 | \n", "0.00 | \n", "0.00 | \n", "0.1512 | \n", "0.5812 | \n", "https://www.strompreis.elcom.admin.ch/municipa... | \n", "
736 | \n", "https://ld.admin.ch/municipality/3423 | \n", "195.02513 | \n", "3.60 | \n", "3.60 | \n", "0.1990 | \n", "0.5871 | \n", "https://www.strompreis.elcom.admin.ch/municipa... | \n", "
615 | \n", "https://ld.admin.ch/municipality/301 | \n", "188.07631 | \n", "3.84 | \n", "4.80 | \n", "0.1887 | \n", "0.5436 | \n", "https://www.strompreis.elcom.admin.ch/municipa... | \n", "
1130 | \n", "https://ld.admin.ch/municipality/4646 | \n", "175.15560 | \n", "3.12 | \n", "3.84 | \n", "0.1928 | \n", "0.5305 | \n", "https://www.strompreis.elcom.admin.ch/municipa... | \n", "
1160 | \n", "https://ld.admin.ch/municipality/4831 | \n", "170.83983 | \n", "3.36 | \n", "3.36 | \n", "0.1917 | \n", "0.5192 | \n", "https://www.strompreis.elcom.admin.ch/municipa... | \n", "