{ "cells": [ { "cell_type": "markdown", "id": "88776377", "metadata": {}, "source": [ "
\n", "\n", "# Economic activities in Zürich\n", "\n", "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 data on economic activities. \n", "We will look into how to query, process, and visualize it. \n" ] }, { "cell_type": "markdown", "id": "2924a8b7", "metadata": {}, "source": [ "[1. Restaurants over time](#Restaurants-over-time) \n", "[2. Restaurants in city quartiers](#Restaurants-in-city-quartiers) \n", "[3. After-school care: gender-representation](#After-school-care:-gender-representation)" ] }, { "cell_type": "markdown", "id": "cb4ca49f", "metadata": {}, "source": [ "### SPARQL endpoint\n", "\n", "Data on some economic activities 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`" ] }, { "cell_type": "code", "execution_count": null, "id": "db0ac7ed", "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": "ede96f69", "metadata": {}, "outputs": [], "source": [ "import mapclassify\n", "import matplotlib\n", "import matplotlib.cm\n", "\n", "import pandas as pd\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "\n", "from graphly.api_client import SparqlClient" ] }, { "cell_type": "code", "execution_count": null, "id": "5fc411a1", "metadata": {}, "outputs": [], "source": [ "sparql = SparqlClient(\"https://ld.stadt-zuerich.ch/query\")\n", "wikisparql = SparqlClient(\"https://query.wikidata.org/sparql\")\n", "\n", "sparql.add_prefixes({\n", " \"schema\": \"