{ "cells": [ { "cell_type": "markdown", "source": [ "
\n", "\n", "# Real estate in Zürich\n", "\n", "the Zürich Statistical Office collects data on the city and its residents. 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 the real estate dataset. \n", "We will look into how to query, process, and visualize it.\n" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "[1. Housing prices](#Housing-prices) \n", " [1.1 Prices per apartment type](#Prices-per-apartment-type) \n", " [1.2 Prices per district](#Prices-per-district) \n", " [1.3 Prices per district and apartment type](#Prices-per-district-and-apartment-type) \n", " [1.4 Prices over time](#Prices-over-time) \n", " [1.5 Prices over time for various apartment types](#Prices-over-time-for-various-apartment-types) \n", "[2. Apartments and population growth](#Apartments-and-population-growth) \n", "[3. Apartment types over time](#Apartment-types-over-time) " ], "metadata": {} }, { "cell_type": "markdown", "source": [ "### SPARQL endpoint\n", "\n", "Data on the real estate market 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://ld.stadt-zuerich.ch/query](https://ld.stadt-zuerich.ch/query).** \n", " \n", " \n", "Let's use `SparqlClient` from [graphly](https://github.com/zazuko/graphly) to communicate with the database. \n", "Graphly will allow us to:\n", "* send SPARQL queries\n", "* automatically add prefixes to all queries\n", "* format response to `pandas` or `geopandas`" ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "# Uncomment to install dependencies in Colab environment\n", "#!pip install git+https://github.com/zazuko/graphly.git" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "import datetime\n", "import re\n", "\n", "import pandas as pd\n", "import numpy as np\n", "\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" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "sparql = SparqlClient(\"https://ld.stadt-zuerich.ch/query\")\n", "sparql.add_prefixes({\n", " \"schema\": \"