{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "cd2f0c7a", "metadata": {}, "source": [ "
\n", "\n", "# Electricity tariffs in Switzerland\n", "\n", "ElCom, the Federal Electricity Commission, collects data on the electricity tariffs for households and companies. This data is published as [Linked Data](https://en.wikipedia.org/wiki/Linked_data). \n", "\n", "In this tutorial, we will show **how to work with Linked Data.** Mainly, we will see how to work with data on electricity tariffs. \n", "We will look into how to query, process, and visualize it. \n" ] }, { "attachments": {}, "cell_type": "markdown", "id": "9d51691e", "metadata": {}, "source": [ "[1. Setup](#Setup) \n", " [1.1 SPARQL endpoints](#SPARQL-endpoints) \n", " [1.2 SPARQL client](#SPARQL-endpoints) \n", "\n", "[2. Data](#Data) \n", " [2.1 Electricity tariffs](#Electricity-tariffs) \n", " [2.2 Municipalities](#Municipalities) \n", "\n", "\n", "[3. Analysis](#Analysis) \n", "\n", "\n", " [3.1 Energy prices across regions](#Energy-prices-across-regions) \n", " [3.2 Energy prices for small and big enterprises](#Energy-prices-for-small-and-big-enterprises) \n", " [3.3 Energy prices for small and big households](#Energy-prices-for-small-and-big-households) \n", " [3.4 Competition between energy providers](#Competition-between-energy-providers) \n", " [3.5 Grid costs and population density](#Grid-costs-and-population-density) \n", " [3.6 Free grid usage](#Free-grid-usage) \n", " [3.7 Free energy](#Free-energy) \n", " [3.8 Free aidfee](#Free-aidfee) \n", " [3.9 How many people benefit from fee waivers?](#How-many-people-benefit-from-fee-waivers?) \n", " [3.10 Which companies benefit from fee waivers?](#Which-companies-benefit-from-fee-waivers?) \n", "\n", "-------------------------------------------------------------------------------------------------------------------" ] }, { "attachments": {}, "cell_type": "markdown", "id": "eb7bef9c", "metadata": {}, "source": [ "## Setup" ] }, { "attachments": {}, "cell_type": "markdown", "id": "cc8bbfa9", "metadata": {}, "source": [ "### SPARQL endpoints\n", "\n", "#### For electricity tariffs\n", "Data on all electricity tariffs are published as Linked Data. They 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 the API endpoint under **[https://geo.ld.admin.ch/query](https://geo.ld.admin.ch/query).** " ] }, { "attachments": {}, "cell_type": "markdown", "id": "da9db59c", "metadata": {}, "source": [ "### SPARQL client\n", "\n", "Let's use `SparqlClient` from [graphly](https://github.com/zazuko/graphly) to communicate with both databases.\n", "Graphly will allow us to:\n", "* send SPARQL queries\n", "* automatically add prefixes to all queries\n", "* format responses to `pandas` or `geopandas`" ] }, { "cell_type": "code", "execution_count": null, "id": "d2f8138f", "metadata": {}, "outputs": [], "source": [ "import json\n", "import re\n", "import string\n", "\n", "import folium\n", "import mapclassify\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "from plotly.subplots import make_subplots\n", "\n", "from graphly.api_client import SparqlClient\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "id": "f80432ff", "metadata": {}, "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": "code", "execution_count": null, "id": "55a2bac1", "metadata": {}, "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\": \"