{ "cells": [ { "cell_type": "markdown", "id": "5dae00ab", "metadata": {}, "source": [ "# Montenegrin Independence Referendum" ] }, { "cell_type": "markdown", "id": "eaacf775", "metadata": {}, "source": [ "Let's explore the results of the Montenegrin independence referendum in 2006.\n", "\n", "The dataset was downloaded from Wikipedia article\n", "[\"2006 Montenegrin independence referendum\"](https://en.wikipedia.org/wiki/2006_Montenegrin_independence_referendum)." ] }, { "cell_type": "code", "execution_count": 1, "id": "ade29f8d", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:13:42.118902Z", "iopub.status.busy": "2026-01-27T17:13:42.118827Z", "iopub.status.idle": "2026-01-27T17:13:42.121555Z", "shell.execute_reply": "2026-01-27T17:13:42.121322Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "ec0a99bf", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:13:42.122456Z", "iopub.status.busy": "2026-01-27T17:13:42.122385Z", "iopub.status.idle": "2026-01-27T17:13:42.124199Z", "shell.execute_reply": "2026-01-27T17:13:42.123766Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html() " ] }, { "cell_type": "code", "execution_count": 3, "id": "f9e8d752-506c-4f73-b0ec-522fb3e4f7e3", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:13:42.125137Z", "iopub.status.busy": "2026-01-27T17:13:42.125067Z", "iopub.status.idle": "2026-01-27T17:13:42.127010Z", "shell.execute_reply": "2026-01-27T17:13:42.126806Z" } }, "outputs": [], "source": [ "def get_data(df):\n", " # Blank or invalid votes:\n", " df[\"Blank\"] = df[\"Voted\"] - df[\"Yes\"] - df[\"No\"]\n", " df = df[[\"Municipality\", \"Registered\", \"No\", \"Yes\", \"Blank\"]]\n", " return pd.melt(df, id_vars=[\"Municipality\", \"Registered\"], var_name=\"Vote\", value_name=\"Number\")\n", "\n", "def get_geodata(df):\n", " from lets_plot.geo_data import geocode_states\n", " country = \"Montenegro\"\n", " municipalities_geocoder = geocode_states(names=df[\"Municipality\"]).scope(country)\n", " return municipalities_geocoder, pd.merge(\n", " municipalities_geocoder.get_boundaries(resolution=15),\n", " df[[\"Municipality\", \"Yes%\"]],\n", " left_on=\"state\",\n", " right_on=\"Municipality\"\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "id": "18e79c96", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:13:42.127704Z", "iopub.status.busy": "2026-01-27T17:13:42.127636Z", "iopub.status.idle": "2026-01-27T17:13:43.195857Z", "shell.execute_reply": "2026-01-27T17:13:43.195454Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n" ] } ], "source": [ "raw_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/montenegrin_referendum_2006.csv\")\n", "df = get_data(raw_df)\n", "municipalities_geocoder, boundaries_gdf = get_geodata(raw_df)" ] }, { "cell_type": "code", "execution_count": 5, "id": "8c2eefa3", "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:13:43.197257Z", "iopub.status.busy": "2026-01-27T17:13:43.197174Z", "iopub.status.idle": "2026-01-27T17:13:43.474109Z", "shell.execute_reply": "2026-01-27T17:13:43.473754Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "