{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e80a69d4",
   "metadata": {},
   "source": [
    "# Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "1f3af25b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import networkx as nx\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from geopy.geocoders import Nominatim"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da489513",
   "metadata": {},
   "source": [
    "# Vars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "08af4393",
   "metadata": {},
   "outputs": [],
   "source": [
    "cooc_path = \"../data/cooccurence_matrix.csv\"\n",
    "count_path = \"../raw_data/tweet_count.csv\"\n",
    "geo_path = \"../data/polizei_accounts_geo.csv\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fee5a4cb",
   "metadata": {},
   "source": [
    "# Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "9ff17b13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>lka_bayern</th>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>München</td>\n",
       "      <td>48.135.125</td>\n",
       "      <td>11.581.981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bepo</th>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bw</th>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Baden-Württemberg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_by</th>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_me</th>\n",
       "      <td>Polizei</td>\n",
       "      <td>Nordrhein-Westfalen</td>\n",
       "      <td>Mettmann</td>\n",
       "      <td>512.527.778</td>\n",
       "      <td>69.777.778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeibb_e</th>\n",
       "      <td>Polizei</td>\n",
       "      <td>Brandenburg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeiobs</th>\n",
       "      <td>Polizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>Rosenheim</td>\n",
       "      <td>478.539.273</td>\n",
       "      <td>12.127.262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_nb</th>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Neubrandenburg</td>\n",
       "      <td>535.574.458</td>\n",
       "      <td>132.602.781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_ros</th>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Rostock</td>\n",
       "      <td>540.924.445</td>\n",
       "      <td>121.286.127</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>162 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Typ              Bundesland           Stadt  \\\n",
       "handle                                                                      \n",
       "lka_bayern      Landeskriminalamt                  Bayern         München   \n",
       "bpol_bepo           Bundespolizei                     NaN             NaN   \n",
       "bpol_bw             Bundespolizei       Baden-Württemberg             NaN   \n",
       "bpol_by             Bundespolizei                  Bayern             NaN   \n",
       "bpol_b              Bundespolizei                  Berlin             NaN   \n",
       "...                           ...                     ...             ...   \n",
       "polizei_nrw_me            Polizei     Nordrhein-Westfalen        Mettmann   \n",
       "polizeibb_e               Polizei             Brandenburg             NaN   \n",
       "polizeiobs                Polizei                  Bayern       Rosenheim   \n",
       "polizei_pp_nb    Polizeipräsidium  Mecklenburg-Vorpommern  Neubrandenburg   \n",
       "polizei_pp_ros   Polizeipräsidium  Mecklenburg-Vorpommern         Rostock   \n",
       "\n",
       "                        LAT         LONG  \n",
       "handle                                    \n",
       "lka_bayern       48.135.125   11.581.981  \n",
       "bpol_bepo               NaN          NaN  \n",
       "bpol_bw                 NaN          NaN  \n",
       "bpol_by                 NaN          NaN  \n",
       "bpol_b                  NaN          NaN  \n",
       "...                     ...          ...  \n",
       "polizei_nrw_me  512.527.778   69.777.778  \n",
       "polizeibb_e             NaN          NaN  \n",
       "polizeiobs      478.539.273   12.127.262  \n",
       "polizei_pp_nb   535.574.458  132.602.781  \n",
       "polizei_pp_ros  540.924.445  121.286.127  \n",
       "\n",
       "[162 rows x 5 columns]"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo = pd.read_csv(geo_path, sep=\"\\t\", encoding=\"utf-16\")\n",
    "geo.set_index(\"handle\", inplace=True, drop=True)\n",
    "geo.drop(\"name\", axis=1, inplace=True)\n",
    "geo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "8519e790",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_count</th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>lka_bayern</th>\n",
       "      <td>120</td>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>München</td>\n",
       "      <td>48.135.125</td>\n",
       "      <td>11.581.981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bepo</th>\n",
       "      <td>30</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bw</th>\n",
       "      <td>660</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Baden-Württemberg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_by</th>\n",
       "      <td>439</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>227</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_me</th>\n",
       "      <td>789</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Nordrhein-Westfalen</td>\n",
       "      <td>Mettmann</td>\n",
       "      <td>512.527.778</td>\n",
       "      <td>69.777.778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeibb_e</th>\n",
       "      <td>68</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Brandenburg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeiobs</th>\n",
       "      <td>169</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>Rosenheim</td>\n",
       "      <td>478.539.273</td>\n",
       "      <td>12.127.262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_nb</th>\n",
       "      <td>231</td>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Neubrandenburg</td>\n",
       "      <td>535.574.458</td>\n",
       "      <td>132.602.781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_ros</th>\n",
       "      <td>119</td>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Rostock</td>\n",
       "      <td>540.924.445</td>\n",
       "      <td>121.286.127</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>162 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                tweet_count                Typ              Bundesland  \\\n",
       "handle                                                                   \n",
       "lka_bayern              120  Landeskriminalamt                  Bayern   \n",
       "bpol_bepo                30      Bundespolizei                     NaN   \n",
       "bpol_bw                 660      Bundespolizei       Baden-Württemberg   \n",
       "bpol_by                 439      Bundespolizei                  Bayern   \n",
       "bpol_b                  227      Bundespolizei                  Berlin   \n",
       "...                     ...                ...                     ...   \n",
       "polizei_nrw_me          789            Polizei     Nordrhein-Westfalen   \n",
       "polizeibb_e              68            Polizei             Brandenburg   \n",
       "polizeiobs              169            Polizei                  Bayern   \n",
       "polizei_pp_nb           231   Polizeipräsidium  Mecklenburg-Vorpommern   \n",
       "polizei_pp_ros          119   Polizeipräsidium  Mecklenburg-Vorpommern   \n",
       "\n",
       "                         Stadt          LAT         LONG  \n",
       "handle                                                    \n",
       "lka_bayern             München   48.135.125   11.581.981  \n",
       "bpol_bepo                  NaN          NaN          NaN  \n",
       "bpol_bw                    NaN          NaN          NaN  \n",
       "bpol_by                    NaN          NaN          NaN  \n",
       "bpol_b                     NaN          NaN          NaN  \n",
       "...                        ...          ...          ...  \n",
       "polizei_nrw_me        Mettmann  512.527.778   69.777.778  \n",
       "polizeibb_e                NaN          NaN          NaN  \n",
       "polizeiobs           Rosenheim  478.539.273   12.127.262  \n",
       "polizei_pp_nb   Neubrandenburg  535.574.458  132.602.781  \n",
       "polizei_pp_ros         Rostock  540.924.445  121.286.127  \n",
       "\n",
       "[162 rows x 6 columns]"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get tweet count\n",
    "accounts = pd.read_csv(count_path, index_col=\"handle\")\n",
    "accounts.index = accounts.index.str.lower()\n",
    "#accuonts = accounts.join(geo, how=\"outer\")\n",
    "accounts = accounts.join(geo, rsuffix=\"_r\")\n",
    "accounts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "0799279a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#geolocator = Nominatim(user_agent=\"copbird-reverse-city-search\")\n",
    "\n",
    "#for handle, row in accounts.iterrows():\n",
    "#    if not pd.isnull(row.Stadt):\n",
    "#        query = row.Stadt\n",
    "#    else: \n",
    "#        query = row[\"name\"]\n",
    "    \n",
    "#    print(f\"Looking for: {query}...\")\n",
    "        \n",
    "#    try:\n",
    "#        location = geolocator.geocode(query)\n",
    "#        accounts.loc[handle, \"LAT\"] = location.latitude\n",
    "#        accounts.loc[handle, \"LONG\"] = location.longitude\n",
    "#    except:\n",
    "#        pass\n",
    "    \n",
    "#accounts.to_csv(\"../data/geocoded_accounts.csv\", encoding=\"utf-8\")\n",
    "accounts = pd.read_csv(\"../data/geocoded_accounts.csv\")   \n",
    "accounts.set_index(\"handle\", inplace=True, drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "0ce408d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bpol_11</th>\n",
       "      <th>bpol_air_fra</th>\n",
       "      <th>bpol_b</th>\n",
       "      <th>bpol_b_einsatz</th>\n",
       "      <th>bpol_bepo</th>\n",
       "      <th>bpol_bw</th>\n",
       "      <th>bpol_by</th>\n",
       "      <th>bpol_koblenz</th>\n",
       "      <th>bpol_kueste</th>\n",
       "      <th>bpol_nord</th>\n",
       "      <th>...</th>\n",
       "      <th>polizeiswn</th>\n",
       "      <th>polizeisws</th>\n",
       "      <th>polizeitrier</th>\n",
       "      <th>polizeiufr</th>\n",
       "      <th>polizeiul</th>\n",
       "      <th>polizeivg</th>\n",
       "      <th>polizeiwittlich</th>\n",
       "      <th>pp_rheinpfalz</th>\n",
       "      <th>pp_stuttgart</th>\n",
       "      <th>sh_polizei</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>bpol_11</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_air_fra</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b_einsatz</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bepo</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 163 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                bpol_11  bpol_air_fra  bpol_b  bpol_b_einsatz  bpol_bepo  \\\n",
       "bpol_11             1.0           0.0     5.0             1.0        0.0   \n",
       "bpol_air_fra        0.0           1.0     1.0             0.0        0.0   \n",
       "bpol_b              4.0           0.0     0.0             2.0        2.0   \n",
       "bpol_b_einsatz      1.0           0.0     0.0             0.0        1.0   \n",
       "bpol_bepo           1.0           1.0     1.0             0.0        0.0   \n",
       "\n",
       "                bpol_bw  bpol_by  bpol_koblenz  bpol_kueste  bpol_nord  ...  \\\n",
       "bpol_11             0.0      0.0           1.0          8.0        2.0  ...   \n",
       "bpol_air_fra        4.0      2.0           5.0          2.0        2.0  ...   \n",
       "bpol_b              2.0      0.0           0.0          3.0        3.0  ...   \n",
       "bpol_b_einsatz      0.0      0.0           0.0          0.0        0.0  ...   \n",
       "bpol_bepo           1.0      1.0           0.0          0.0        0.0  ...   \n",
       "\n",
       "                polizeiswn  polizeisws  polizeitrier  polizeiufr  polizeiul  \\\n",
       "bpol_11                0.0         0.0           0.0         0.0        1.0   \n",
       "bpol_air_fra           0.0         0.0           0.0         0.0        0.0   \n",
       "bpol_b                 0.0         0.0           0.0         0.0        1.0   \n",
       "bpol_b_einsatz         0.0         0.0           0.0         0.0        0.0   \n",
       "bpol_bepo              0.0         0.0           0.0         0.0        0.0   \n",
       "\n",
       "                polizeivg  polizeiwittlich  pp_rheinpfalz  pp_stuttgart  \\\n",
       "bpol_11               0.0              0.0            0.0           0.0   \n",
       "bpol_air_fra          0.0              0.0            0.0           0.0   \n",
       "bpol_b                0.0              0.0            0.0           0.0   \n",
       "bpol_b_einsatz        0.0              0.0            0.0           0.0   \n",
       "bpol_bepo             0.0              0.0            0.0           0.0   \n",
       "\n",
       "                sh_polizei  \n",
       "bpol_11                0.0  \n",
       "bpol_air_fra           0.0  \n",
       "bpol_b                 0.0  \n",
       "bpol_b_einsatz         0.0  \n",
       "bpol_bepo              0.0  \n",
       "\n",
       "[5 rows x 163 columns]"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cooc_matrix = pd.read_csv(cooc_path, sep=\";\", index_col=[0]).fillna(0) \n",
    "cooc_matrix.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "c45345ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "network = nx.from_pandas_adjacency(cooc_matrix, create_using=nx.DiGraph)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "e16382aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "colors = {\n",
    "    'Landeskriminalamt': (1,0,0), \n",
    "    'Bundespolizei': (0,1,0), \n",
    "    'Polizei': (0,0,1),\n",
    "       'Polizeipräsidium': (.5,.50,.50)\n",
    "}\n",
    "\n",
    "node_colors = []\n",
    "\n",
    "for node in network.nodes:\n",
    "    if str(node) in accounts.index:\n",
    "        node_colors.append(colors.get(accounts.loc[str(node), \"Typ\"]))\n",
    "    else:\n",
    "        node_colors.append((.9,.9,.9))\n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "id": "b88e2779",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1084152 characters]\n",
      "text/plain": [
       "<Figure size 2160x2160 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(30,30))\n",
    "\n",
    "centrality = dict(nx.pagerank(network))\n",
    "closeness_node_sizes = np.fromiter(centrality.values(), dtype=float) * 10000\n",
    "\n",
    "pos = nx.spring_layout(network, k=.2)\n",
    "nx.draw(network, pos=pos, with_labels=True,\n",
    "        edge_color = (.1,.1,.1,.1), node_color=node_colors, \n",
    "       node_size=closeness_node_sizes) \n",
    "\n",
    "\n",
    "plt.savefig(\"../res/imgs/force_directed_fullgraph.svg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "950a2adb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.06574263424979171"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nx.density(network)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "f6cf2960",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'bpol_11',\n",
       "  'bpol_air_fra',\n",
       "  'bpol_b',\n",
       "  'bpol_b_einsatz',\n",
       "  'bpol_bepo',\n",
       "  'bpol_bw',\n",
       "  'bpol_by',\n",
       "  'bpol_koblenz',\n",
       "  'bpol_kueste',\n",
       "  'bpol_nord',\n",
       "  'bpol_nrw',\n",
       "  'bpol_pir',\n",
       "  'bremenpolizei',\n",
       "  'lka_bayern',\n",
       "  'lka_hessen',\n",
       "  'lka_rlp',\n",
       "  'lkabawue',\n",
       "  'pol_grafschaft',\n",
       "  'polizei_aur_wtm',\n",
       "  'polizei_badn',\n",
       "  'polizei_bbg',\n",
       "  'polizei_bs',\n",
       "  'polizei_ce',\n",
       "  'polizei_clp_vec',\n",
       "  'polizei_cux',\n",
       "  'polizei_del',\n",
       "  'polizei_dero',\n",
       "  'polizei_dh',\n",
       "  'polizei_el',\n",
       "  'polizei_ffm',\n",
       "  'polizei_ft',\n",
       "  'polizei_ger',\n",
       "  'polizei_gf',\n",
       "  'polizei_goe',\n",
       "  'polizei_gs',\n",
       "  'polizei_h',\n",
       "  'polizei_hal',\n",
       "  'polizei_hi',\n",
       "  'polizei_hk',\n",
       "  'polizei_hm',\n",
       "  'polizei_hol',\n",
       "  'polizei_hst',\n",
       "  'polizei_ka',\n",
       "  'polizei_kl',\n",
       "  'polizei_ko',\n",
       "  'polizei_ler_emd',\n",
       "  'polizei_lg',\n",
       "  'polizei_md',\n",
       "  'polizei_mh',\n",
       "  'polizei_mse',\n",
       "  'polizei_nbg',\n",
       "  'polizei_nh',\n",
       "  'polizei_nom',\n",
       "  'polizei_nrw_ac',\n",
       "  'polizei_nrw_bi',\n",
       "  'polizei_nrw_bn',\n",
       "  'polizei_nrw_bo',\n",
       "  'polizei_nrw_bor',\n",
       "  'polizei_nrw_coe',\n",
       "  'polizei_nrw_d',\n",
       "  'polizei_nrw_dn',\n",
       "  'polizei_nrw_do',\n",
       "  'polizei_nrw_du',\n",
       "  'polizei_nrw_e',\n",
       "  'polizei_nrw_eu',\n",
       "  'polizei_nrw_ge',\n",
       "  'polizei_nrw_gm',\n",
       "  'polizei_nrw_gt',\n",
       "  'polizei_nrw_ha',\n",
       "  'polizei_nrw_ham',\n",
       "  'polizei_nrw_hf',\n",
       "  'polizei_nrw_hs',\n",
       "  'polizei_nrw_hsk',\n",
       "  'polizei_nrw_hx',\n",
       "  'polizei_nrw_k',\n",
       "  'polizei_nrw_kle',\n",
       "  'polizei_nrw_kr',\n",
       "  'polizei_nrw_lip',\n",
       "  'polizei_nrw_lka',\n",
       "  'polizei_nrw_me',\n",
       "  'polizei_nrw_mg',\n",
       "  'polizei_nrw_mi',\n",
       "  'polizei_nrw_mk',\n",
       "  'polizei_nrw_ms',\n",
       "  'polizei_nrw_ob',\n",
       "  'polizei_nrw_pb',\n",
       "  'polizei_nrw_re',\n",
       "  'polizei_nrw_rek',\n",
       "  'polizei_nrw_rkn',\n",
       "  'polizei_nrw_si',\n",
       "  'polizei_nrw_so',\n",
       "  'polizei_nrw_st',\n",
       "  'polizei_nrw_su',\n",
       "  'polizei_nrw_un',\n",
       "  'polizei_nrw_vie',\n",
       "  'polizei_nrw_w',\n",
       "  'polizei_nrw_waf',\n",
       "  'polizei_nrw_wes',\n",
       "  'polizei_oh',\n",
       "  'polizei_oha',\n",
       "  'polizei_ol',\n",
       "  'polizei_os',\n",
       "  'polizei_pp_nb',\n",
       "  'polizei_pp_ros',\n",
       "  'polizei_ps',\n",
       "  'polizei_rostock',\n",
       "  'polizei_row',\n",
       "  'polizei_sdl',\n",
       "  'polizei_sn',\n",
       "  'polizei_soh',\n",
       "  'polizei_std',\n",
       "  'polizei_sth',\n",
       "  'polizei_suedhe',\n",
       "  'polizei_sz',\n",
       "  'polizei_thuer',\n",
       "  'polizei_ver_ohz',\n",
       "  'polizei_wh',\n",
       "  'polizei_whv_fri',\n",
       "  'polizei_wl',\n",
       "  'polizei_wob',\n",
       "  'polizei_zpd_ni',\n",
       "  'polizeiaalen',\n",
       "  'polizeibayern',\n",
       "  'polizeibb',\n",
       "  'polizeibb_e',\n",
       "  'polizeiberlin',\n",
       "  'polizeiberlin_e',\n",
       "  'polizeiberlin_p',\n",
       "  'polizeibhv',\n",
       "  'polizeifr',\n",
       "  'polizeihamburg',\n",
       "  'polizeihn',\n",
       "  'polizeikonstanz',\n",
       "  'polizeilb',\n",
       "  'polizeimainz',\n",
       "  'polizeimannheim',\n",
       "  'polizeimfr',\n",
       "  'polizeimuenchen',\n",
       "  'polizeinb',\n",
       "  'polizeineustadt',\n",
       "  'polizeini_lka',\n",
       "  'polizeiobn',\n",
       "  'polizeiobs',\n",
       "  'polizeiofr',\n",
       "  'polizeiog',\n",
       "  'polizeiopf',\n",
       "  'polizeipf',\n",
       "  'polizeirt',\n",
       "  'polizeirv',\n",
       "  'polizeisaarland',\n",
       "  'polizeisachsen',\n",
       "  'polizeiswn',\n",
       "  'polizeisws',\n",
       "  'polizeitrier',\n",
       "  'polizeiufr',\n",
       "  'polizeiul',\n",
       "  'polizeivg',\n",
       "  'polizeiwittlich',\n",
       "  'pp_rheinpfalz',\n",
       "  'pp_stuttgart',\n",
       "  'sh_polizei'},\n",
       " {'polizei_nrw_en'},\n",
       " {'polizei_nrw_rbk'}]"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g2 = nx.Graph(network)\n",
    "nx.number_connected_components(g2)\n",
    "list(nx.connected_components(g2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "890d06d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0996743164432326"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nx.density(g2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "2e06b33c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Knoten:161, Durchmesser: 5\n",
      "Knoten:1, Durchmesser: 0\n",
      "Knoten:1, Durchmesser: 0\n"
     ]
    }
   ],
   "source": [
    "S = [g2.subgraph(c).copy() for c in nx.connected_components(g2)]\n",
    "\n",
    "for s in S:\n",
    "    print(f\"Knoten:{len(s.nodes)}, Durchmesser: {nx.diameter(s)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "20152b25",
   "metadata": {},
   "outputs": [],
   "source": [
    "accounts = accounts.join(pd.DataFrame.from_dict(centrality, orient=\"index\", columns=[\"pagerank\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "d798e715",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>degree</th>\n",
       "      <th>indegree</th>\n",
       "      <th>outdegree</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>bpol_11</th>\n",
       "      <td>23</td>\n",
       "      <td>13</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_air_fra</th>\n",
       "      <td>24</td>\n",
       "      <td>11</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>37</td>\n",
       "      <td>20</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b_einsatz</th>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bepo</th>\n",
       "      <td>19</td>\n",
       "      <td>12</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_lka</th>\n",
       "      <td>13</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_mg</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_mi</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_so</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeiberlin_p</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>163 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                degree indegree outdegree\n",
       "handle                                   \n",
       "bpol_11             23       13        10\n",
       "bpol_air_fra        24       11        13\n",
       "bpol_b              37       20        17\n",
       "bpol_b_einsatz       8        4         4\n",
       "bpol_bepo           19       12         7\n",
       "...                ...      ...       ...\n",
       "polizei_nrw_lka     13       13         0\n",
       "polizei_nrw_mg       5        5         0\n",
       "polizei_nrw_mi       2        2         0\n",
       "polizei_nrw_so       1        1         0\n",
       "polizeiberlin_p      4        4         0\n",
       "\n",
       "[163 rows x 3 columns]"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "degrees = pd.DataFrame(network.degree(), columns=(\"handle\", \"degree\"))\n",
    "indegrees = pd.DataFrame(network.in_degree(), columns=(\"handle\", \"indegree\"))\n",
    "outdegrees = pd.DataFrame(network.out_degree(), columns=(\"handle\", \"outdegree\"))\n",
    "\n",
    "degrees = pd.concat([degrees,indegrees, outdegrees], axis=1)\n",
    "degrees = degrees.transpose().drop_duplicates().transpose()\n",
    "\n",
    "degrees.set_index(\"handle\", drop=True, inplace=True)\n",
    "degrees"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "1c5f36df",
   "metadata": {},
   "outputs": [],
   "source": [
    "accounts = accounts.join(degrees)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "8b6a1593",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_count</th>\n",
       "      <th>name</th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>degree</th>\n",
       "      <th>indegree</th>\n",
       "      <th>outdegree</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>lka_bayern</th>\n",
       "      <td>120</td>\n",
       "      <td>Bayerisches Landeskriminalamt</td>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>München</td>\n",
       "      <td>48.137108</td>\n",
       "      <td>11.575382</td>\n",
       "      <td>0.011841</td>\n",
       "      <td>31</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bepo</th>\n",
       "      <td>30</td>\n",
       "      <td>Bundesbereitschaftspolizei</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>51.360890</td>\n",
       "      <td>9.499035</td>\n",
       "      <td>0.008283</td>\n",
       "      <td>19</td>\n",
       "      <td>12</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_bw</th>\n",
       "      <td>660</td>\n",
       "      <td>Bundespolizei Baden-Württember</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Baden-Württemberg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.009224</td>\n",
       "      <td>50</td>\n",
       "      <td>26</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_by</th>\n",
       "      <td>439</td>\n",
       "      <td>Bundespolizei Bayern</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>NaN</td>\n",
       "      <td>49.332204</td>\n",
       "      <td>12.118197</td>\n",
       "      <td>0.004999</td>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>227</td>\n",
       "      <td>Bundespolizei Berlin</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52.509475</td>\n",
       "      <td>13.435332</td>\n",
       "      <td>0.014181</td>\n",
       "      <td>37</td>\n",
       "      <td>20</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_me</th>\n",
       "      <td>789</td>\n",
       "      <td>polizei_nrw_me</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Nordrhein-Westfalen</td>\n",
       "      <td>Mettmann</td>\n",
       "      <td>51.252778</td>\n",
       "      <td>6.977778</td>\n",
       "      <td>0.002113</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeibb_e</th>\n",
       "      <td>68</td>\n",
       "      <td>PolizeiBrandenburg_E</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Brandenburg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.001929</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeiobs</th>\n",
       "      <td>169</td>\n",
       "      <td>PolizeiOberbayernSüd</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Bayern</td>\n",
       "      <td>Rosenheim</td>\n",
       "      <td>47.853927</td>\n",
       "      <td>12.127262</td>\n",
       "      <td>0.003715</td>\n",
       "      <td>18</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_nb</th>\n",
       "      <td>231</td>\n",
       "      <td>Polizeipräsidium NB</td>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Neubrandenburg</td>\n",
       "      <td>53.557446</td>\n",
       "      <td>13.260278</td>\n",
       "      <td>0.005334</td>\n",
       "      <td>21</td>\n",
       "      <td>10</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_pp_ros</th>\n",
       "      <td>119</td>\n",
       "      <td>Polizeipräsidium Rostock</td>\n",
       "      <td>Polizeipräsidium</td>\n",
       "      <td>Mecklenburg-Vorpommern</td>\n",
       "      <td>Rostock</td>\n",
       "      <td>54.092444</td>\n",
       "      <td>12.128613</td>\n",
       "      <td>0.004543</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>162 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                tweet_count                            name  \\\n",
       "handle                                                        \n",
       "lka_bayern              120   Bayerisches Landeskriminalamt   \n",
       "bpol_bepo                30      Bundesbereitschaftspolizei   \n",
       "bpol_bw                 660  Bundespolizei Baden-Württember   \n",
       "bpol_by                 439            Bundespolizei Bayern   \n",
       "bpol_b                  227            Bundespolizei Berlin   \n",
       "...                     ...                             ...   \n",
       "polizei_nrw_me          789                  polizei_nrw_me   \n",
       "polizeibb_e              68            PolizeiBrandenburg_E   \n",
       "polizeiobs              169            PolizeiOberbayernSüd   \n",
       "polizei_pp_nb           231             Polizeipräsidium NB   \n",
       "polizei_pp_ros          119        Polizeipräsidium Rostock   \n",
       "\n",
       "                              Typ              Bundesland           Stadt  \\\n",
       "handle                                                                      \n",
       "lka_bayern      Landeskriminalamt                  Bayern         München   \n",
       "bpol_bepo           Bundespolizei                     NaN             NaN   \n",
       "bpol_bw             Bundespolizei       Baden-Württemberg             NaN   \n",
       "bpol_by             Bundespolizei                  Bayern             NaN   \n",
       "bpol_b              Bundespolizei                  Berlin             NaN   \n",
       "...                           ...                     ...             ...   \n",
       "polizei_nrw_me            Polizei     Nordrhein-Westfalen        Mettmann   \n",
       "polizeibb_e               Polizei             Brandenburg             NaN   \n",
       "polizeiobs                Polizei                  Bayern       Rosenheim   \n",
       "polizei_pp_nb    Polizeipräsidium  Mecklenburg-Vorpommern  Neubrandenburg   \n",
       "polizei_pp_ros   Polizeipräsidium  Mecklenburg-Vorpommern         Rostock   \n",
       "\n",
       "                      LAT       LONG  pagerank degree indegree outdegree  \n",
       "handle                                                                    \n",
       "lka_bayern      48.137108  11.575382  0.011841     31       15        16  \n",
       "bpol_bepo       51.360890   9.499035  0.008283     19       12         7  \n",
       "bpol_bw               NaN        NaN  0.009224     50       26        24  \n",
       "bpol_by         49.332204  12.118197  0.004999     27       12        15  \n",
       "bpol_b          52.509475  13.435332  0.014181     37       20        17  \n",
       "...                   ...        ...       ...    ...      ...       ...  \n",
       "polizei_nrw_me  51.252778   6.977778  0.002113     14        5         9  \n",
       "polizeibb_e           NaN        NaN  0.001929      7        3         4  \n",
       "polizeiobs      47.853927  12.127262  0.003715     18        9         9  \n",
       "polizei_pp_nb   53.557446  13.260278  0.005334     21       10        11  \n",
       "polizei_pp_ros  54.092444  12.128613  0.004543      8        4         4  \n",
       "\n",
       "[162 rows x 11 columns]"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "bda631a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Outdegree')"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 15360 characters]\n",
      "text/plain": [
       "<Figure size 1512x504 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Figures are the container for multiple plots\n",
    "fig = plt.figure(figsize=(21,7))\n",
    "# Add some sub-plots (called axes)\n",
    "axs1 = fig.add_subplot(1, 3, 1) # 1x3 grid, position 1\n",
    "axs2 = fig.add_subplot(1, 3, 2)\n",
    "axs3 = fig.add_subplot(1, 3, 3)\n",
    "\n",
    "accounts.degree.hist(ax = axs1)\n",
    "accounts.indegree.hist(ax = axs2)\n",
    "accounts.outdegree.hist(ax = axs3)\n",
    "\n",
    "axs1.set_title(\"Degree\")\n",
    "axs2.set_title(\"Indegree\")\n",
    "axs3.set_title(\"Outdegree\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "3c414400",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "handle\n",
       "polizeini_lka      44\n",
       "polizeimuenchen    42\n",
       "polizeipf          41\n",
       "polizeihamburg     37\n",
       "polizeiberlin      34\n",
       "                   ..\n",
       "polizei_nrw_wes     1\n",
       "polizei_nrw_rbk     1\n",
       "polizei_nrw_dn      1\n",
       "polizeibhv          1\n",
       "polizei_nrw_so      1\n",
       "Name: indegree, Length: 161, dtype: object"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts.indegree.dropna().sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "253fa71b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "handle\n",
       "polizeimuenchen    46\n",
       "polizei_ffm        39\n",
       "polizei_h          35\n",
       "polizei_goe        28\n",
       "lkabawue           27\n",
       "                   ..\n",
       "polizeiberlin_e     1\n",
       "polizei_nrw_so      0\n",
       "polizei_nrw_mi      0\n",
       "polizei_nrw_mg      0\n",
       "polizei_nrw_kle     0\n",
       "Name: outdegree, Length: 161, dtype: object"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts.outdegree.dropna().sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "2c7e9d7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Outdegree vs. #tweets')"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 35720 characters]\n",
      "text/plain": [
       "<Figure size 1512x504 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Figures are the container for multiple plots\n",
    "fig = plt.figure(figsize=(21,7))\n",
    "# Add some sub-plots (called axes)\n",
    "axs1 = fig.add_subplot(1, 3, 1) # 1x3 grid, position 1\n",
    "axs2 = fig.add_subplot(1, 3, 2)\n",
    "axs3 = fig.add_subplot(1, 3, 3)\n",
    "\n",
    "axs1.scatter(accounts.tweet_count, accounts.degree)\n",
    "axs2.scatter(accounts.tweet_count, accounts.indegree)\n",
    "axs3.scatter(accounts.tweet_count, accounts.outdegree)\n",
    "\n",
    "axs1.set_title(\"Degree vs. #tweets\")\n",
    "axs2.set_title(\"Indegree vs. #tweets\")\n",
    "axs3.set_title(\"Outdegree vs. #tweets\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "e04cfa8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1482236 characters]\n",
      "text/plain": [
       "<Figure size 2160x2160 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(30,30))\n",
    "\n",
    "G = nx.Graph(network.copy())\n",
    "G.remove_edges_from(nx.selfloop_edges(G))\n",
    "core = nx.k_core(G, k=12)\n",
    "#list(nx.connected_components(core))\n",
    "\n",
    "\n",
    "core = [G.subgraph(c).copy() for c in nx.connected_components(core)][0]\n",
    "\n",
    "pos = nx.spring_layout(core, k=1)\n",
    "nx.draw_networkx(core, pos=pos, with_labels=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "id": "97b92d59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4566145092460882"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nx.density(core)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "9b8f1823",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(core.nodes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "id": "09f5af83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_count</th>\n",
       "      <th>name</th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>degree</th>\n",
       "      <th>indegree</th>\n",
       "      <th>outdegree</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>38.000000</td>\n",
       "      <td>38</td>\n",
       "      <td>38</td>\n",
       "      <td>33</td>\n",
       "      <td>26</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>38.000000</td>\n",
       "      <td>38.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>38.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>NaN</td>\n",
       "      <td>38</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>24</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Polizei Südhessen</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Rheinland-Pfalz</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>44.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>17.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>25</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>775.605263</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50.775397</td>\n",
       "      <td>9.780740</td>\n",
       "      <td>0.012135</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>689.881131</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.575879</td>\n",
       "      <td>2.129766</td>\n",
       "      <td>0.007290</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>30.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>48.137108</td>\n",
       "      <td>6.445727</td>\n",
       "      <td>0.002598</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>283.750000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>49.484571</td>\n",
       "      <td>8.429472</td>\n",
       "      <td>0.006842</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>557.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50.469767</td>\n",
       "      <td>9.339524</td>\n",
       "      <td>0.010366</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1078.500000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>51.966866</td>\n",
       "      <td>11.165398</td>\n",
       "      <td>0.014608</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2679.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>54.322708</td>\n",
       "      <td>13.738144</td>\n",
       "      <td>0.036886</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        tweet_count               name      Typ       Bundesland   Stadt  \\\n",
       "count     38.000000                 38       38               33      26   \n",
       "unique          NaN                 38        3               13      24   \n",
       "top             NaN  Polizei Südhessen  Polizei  Rheinland-Pfalz  Berlin   \n",
       "freq            NaN                  1       25                7       2   \n",
       "mean     775.605263                NaN      NaN              NaN     NaN   \n",
       "std      689.881131                NaN      NaN              NaN     NaN   \n",
       "min       30.000000                NaN      NaN              NaN     NaN   \n",
       "25%      283.750000                NaN      NaN              NaN     NaN   \n",
       "50%      557.000000                NaN      NaN              NaN     NaN   \n",
       "75%     1078.500000                NaN      NaN              NaN     NaN   \n",
       "max     2679.000000                NaN      NaN              NaN     NaN   \n",
       "\n",
       "              LAT       LONG   pagerank  degree  indegree  outdegree  \n",
       "count   32.000000  32.000000  38.000000    38.0      38.0       38.0  \n",
       "unique        NaN        NaN        NaN    25.0      23.0       23.0  \n",
       "top           NaN        NaN        NaN    44.0      19.0       17.0  \n",
       "freq          NaN        NaN        NaN     4.0       7.0        4.0  \n",
       "mean    50.775397   9.780740   0.012135     NaN       NaN        NaN  \n",
       "std      1.575879   2.129766   0.007290     NaN       NaN        NaN  \n",
       "min     48.137108   6.445727   0.002598     NaN       NaN        NaN  \n",
       "25%     49.484571   8.429472   0.006842     NaN       NaN        NaN  \n",
       "50%     50.469767   9.339524   0.010366     NaN       NaN        NaN  \n",
       "75%     51.966866  11.165398   0.014608     NaN       NaN        NaN  \n",
       "max     54.322708  13.738144   0.036886     NaN       NaN        NaN  "
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "core_names = [str(c) for c in core.nodes]\n",
    "accounts.loc[core_names].describe(include=\"all\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac1e4726",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "45cdc67e",
   "metadata": {},
   "source": [
    "## Degree vs #tweets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21e949f0",
   "metadata": {},
   "source": [
    "Interessant, scheinbar hängt der Degree nicht unbedingt mit der Gesamtzahl der Tweets zusammen.\n",
    "\n",
    "Scheinbar vernetzen sich al"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "926b1e74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Outdegree')"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 18296 characters]\n",
      "text/plain": [
       "<Figure size 1080x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(15,10))\n",
    "\n",
    "ax = fig.add_subplot(1,1,1)\n",
    "\n",
    "ax.scatter(accounts.indegree, accounts.outdegree)\n",
    "\n",
    "ax.set_xlabel(\"Indegree\")\n",
    "ax.set_ylabel(\"Outdegree\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "13f053f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_count</th>\n",
       "      <th>name</th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>degree</th>\n",
       "      <th>indegree</th>\n",
       "      <th>outdegree</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>polizei_clp_vec</th>\n",
       "      <td>64</td>\n",
       "      <td>Polizei Cloppenburg/Vechta</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Niedersachsen</td>\n",
       "      <td>Cloppenburg</td>\n",
       "      <td>52.846134</td>\n",
       "      <td>8.043878</td>\n",
       "      <td>0.001369</td>\n",
       "      <td>18</td>\n",
       "      <td>3</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_cux</th>\n",
       "      <td>105</td>\n",
       "      <td>Polizei Cuxhaven</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Niedersachsen</td>\n",
       "      <td>Cuxhaven</td>\n",
       "      <td>53.587242</td>\n",
       "      <td>8.884079</td>\n",
       "      <td>0.001950</td>\n",
       "      <td>15</td>\n",
       "      <td>4</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_dh</th>\n",
       "      <td>182</td>\n",
       "      <td>Polizei Diepholz</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Niedersachsen</td>\n",
       "      <td>Diepholz</td>\n",
       "      <td>52.747899</td>\n",
       "      <td>8.761526</td>\n",
       "      <td>0.001181</td>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_vie</th>\n",
       "      <td>358</td>\n",
       "      <td>Polizei NRW VIE</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Nordrhein-Westfalen</td>\n",
       "      <td>Viersen</td>\n",
       "      <td>51.256212</td>\n",
       "      <td>6.390548</td>\n",
       "      <td>0.001065</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 tweet_count                        name      Typ  \\\n",
       "handle                                                              \n",
       "polizei_clp_vec           64  Polizei Cloppenburg/Vechta  Polizei   \n",
       "polizei_cux              105            Polizei Cuxhaven  Polizei   \n",
       "polizei_dh               182            Polizei Diepholz  Polizei   \n",
       "polizei_nrw_vie          358             Polizei NRW VIE  Polizei   \n",
       "\n",
       "                          Bundesland        Stadt        LAT      LONG  \\\n",
       "handle                                                                   \n",
       "polizei_clp_vec        Niedersachsen  Cloppenburg  52.846134  8.043878   \n",
       "polizei_cux            Niedersachsen     Cuxhaven  53.587242  8.884079   \n",
       "polizei_dh             Niedersachsen     Diepholz  52.747899  8.761526   \n",
       "polizei_nrw_vie  Nordrhein-Westfalen      Viersen  51.256212  6.390548   \n",
       "\n",
       "                 pagerank degree indegree outdegree  \n",
       "handle                                               \n",
       "polizei_clp_vec  0.001369     18        3        15  \n",
       "polizei_cux      0.001950     15        4        11  \n",
       "polizei_dh       0.001181     13        2        11  \n",
       "polizei_nrw_vie  0.001065     15        1        14  "
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts.loc[(accounts.indegree < 5) & (accounts.outdegree > 10)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "id": "98589bb9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "handle\n",
       "lkabawue           0.036886\n",
       "polizeini_lka      0.031356\n",
       "polizeiberlin      0.025919\n",
       "polizeimuenchen    0.019073\n",
       "polizei_kl         0.018147\n",
       "                     ...   \n",
       "polizei_nrw_hs     0.001157\n",
       "polizeiwittlich    0.001134\n",
       "polizei_nrw_dn     0.001089\n",
       "polizei_nrw_vie    0.001065\n",
       "polizei_nrw_oe          NaN\n",
       "Name: pagerank, Length: 162, dtype: float64"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts.pagerank.sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "id": "1b04c61a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 5144 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "accounts.pagerank.hist() #sort_values().head(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "be9ee2bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_count</th>\n",
       "      <th>name</th>\n",
       "      <th>Typ</th>\n",
       "      <th>Bundesland</th>\n",
       "      <th>Stadt</th>\n",
       "      <th>LAT</th>\n",
       "      <th>LONG</th>\n",
       "      <th>pagerank</th>\n",
       "      <th>degree</th>\n",
       "      <th>indegree</th>\n",
       "      <th>outdegree</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>handle</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>polizeiberlin</th>\n",
       "      <td>915</td>\n",
       "      <td>Polizei Berlin</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>52.517037</td>\n",
       "      <td>13.388860</td>\n",
       "      <td>0.061571</td>\n",
       "      <td>55</td>\n",
       "      <td>39</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bpol_b</th>\n",
       "      <td>227</td>\n",
       "      <td>Bundespolizei Berlin</td>\n",
       "      <td>Bundespolizei</td>\n",
       "      <td>Berlin</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52.509475</td>\n",
       "      <td>13.435332</td>\n",
       "      <td>0.046513</td>\n",
       "      <td>56</td>\n",
       "      <td>42</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>lkabawue</th>\n",
       "      <td>577</td>\n",
       "      <td>Landeskriminalamt BW</td>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Baden-Württemberg</td>\n",
       "      <td>Stuttgart</td>\n",
       "      <td>48.778449</td>\n",
       "      <td>9.180013</td>\n",
       "      <td>0.035581</td>\n",
       "      <td>60</td>\n",
       "      <td>34</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeini_lka</th>\n",
       "      <td>216</td>\n",
       "      <td>LKA Niedersachsen</td>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Niedersachsen</td>\n",
       "      <td>Hannover</td>\n",
       "      <td>52.374478</td>\n",
       "      <td>9.738553</td>\n",
       "      <td>0.031873</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_h</th>\n",
       "      <td>1328</td>\n",
       "      <td>Polizei Hannover</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Niedersachsen</td>\n",
       "      <td>Hannover</td>\n",
       "      <td>52.374478</td>\n",
       "      <td>9.738553</td>\n",
       "      <td>0.031111</td>\n",
       "      <td>82</td>\n",
       "      <td>50</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizeibb</th>\n",
       "      <td>2040</td>\n",
       "      <td>Polizei Brandenburg</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Brandenburg</td>\n",
       "      <td>NaN</td>\n",
       "      <td>53.117328</td>\n",
       "      <td>13.504988</td>\n",
       "      <td>0.024921</td>\n",
       "      <td>44</td>\n",
       "      <td>25</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_kl</th>\n",
       "      <td>90</td>\n",
       "      <td>Polizei Kaiserslautern</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Rheinland-Pfalz</td>\n",
       "      <td>Kaiserslautern</td>\n",
       "      <td>49.443217</td>\n",
       "      <td>7.768995</td>\n",
       "      <td>0.021072</td>\n",
       "      <td>44</td>\n",
       "      <td>33</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_nrw_bo</th>\n",
       "      <td>1133</td>\n",
       "      <td>Polizei NRW BO</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Nordrhein-Westfalen</td>\n",
       "      <td>Bochum</td>\n",
       "      <td>51.481811</td>\n",
       "      <td>7.219664</td>\n",
       "      <td>0.020550</td>\n",
       "      <td>41</td>\n",
       "      <td>18</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>polizei_ffm</th>\n",
       "      <td>2559</td>\n",
       "      <td>Polizei Frankfurt</td>\n",
       "      <td>Polizei</td>\n",
       "      <td>Hessen</td>\n",
       "      <td>Frankfurt</td>\n",
       "      <td>50.110644</td>\n",
       "      <td>8.682092</td>\n",
       "      <td>0.019821</td>\n",
       "      <td>65</td>\n",
       "      <td>29</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>lka_rlp</th>\n",
       "      <td>279</td>\n",
       "      <td>Landeskriminalamt Rheinland-Pf</td>\n",
       "      <td>Landeskriminalamt</td>\n",
       "      <td>Rheinland-Pfalz</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.019225</td>\n",
       "      <td>31</td>\n",
       "      <td>20</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                tweet_count                            name  \\\n",
       "handle                                                        \n",
       "polizeiberlin           915                  Polizei Berlin   \n",
       "bpol_b                  227            Bundespolizei Berlin   \n",
       "lkabawue                577            Landeskriminalamt BW   \n",
       "polizeini_lka           216               LKA Niedersachsen   \n",
       "polizei_h              1328                Polizei Hannover   \n",
       "polizeibb              2040             Polizei Brandenburg   \n",
       "polizei_kl               90          Polizei Kaiserslautern   \n",
       "polizei_nrw_bo         1133                  Polizei NRW BO   \n",
       "polizei_ffm            2559               Polizei Frankfurt   \n",
       "lka_rlp                 279  Landeskriminalamt Rheinland-Pf   \n",
       "\n",
       "                              Typ           Bundesland           Stadt  \\\n",
       "handle                                                                   \n",
       "polizeiberlin             Polizei               Berlin          Berlin   \n",
       "bpol_b              Bundespolizei               Berlin             NaN   \n",
       "lkabawue        Landeskriminalamt    Baden-Württemberg       Stuttgart   \n",
       "polizeini_lka   Landeskriminalamt        Niedersachsen        Hannover   \n",
       "polizei_h                 Polizei        Niedersachsen        Hannover   \n",
       "polizeibb                 Polizei          Brandenburg             NaN   \n",
       "polizei_kl                Polizei      Rheinland-Pfalz  Kaiserslautern   \n",
       "polizei_nrw_bo            Polizei  Nordrhein-Westfalen          Bochum   \n",
       "polizei_ffm               Polizei               Hessen       Frankfurt   \n",
       "lka_rlp         Landeskriminalamt      Rheinland-Pfalz             NaN   \n",
       "\n",
       "                      LAT       LONG  pagerank degree indegree outdegree  \n",
       "handle                                                                    \n",
       "polizeiberlin   52.517037  13.388860  0.061571     55       39        16  \n",
       "bpol_b          52.509475  13.435332  0.046513     56       42        14  \n",
       "lkabawue        48.778449   9.180013  0.035581     60       34        26  \n",
       "polizeini_lka   52.374478   9.738553  0.031873     66       44        22  \n",
       "polizei_h       52.374478   9.738553  0.031111     82       50        32  \n",
       "polizeibb       53.117328  13.504988  0.024921     44       25        19  \n",
       "polizei_kl      49.443217   7.768995  0.021072     44       33        11  \n",
       "polizei_nrw_bo  51.481811   7.219664  0.020550     41       18        23  \n",
       "polizei_ffm     50.110644   8.682092  0.019821     65       29        36  \n",
       "lka_rlp               NaN        NaN  0.019225     31       20        11  "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accounts.loc[accounts.pagerank.sort_values(ascending=False).head(10).index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "1540a4c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Pagerank')"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 10944 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "\n",
    "ax = fig.add_subplot(1,1,1)\n",
    "\n",
    "ax.scatter(accounts.indegree, accounts.pagerank)\n",
    "\n",
    "ax.set_xlabel(\"Indegree\")\n",
    "ax.set_ylabel(\"Pagerank\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "47ac2794",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1736"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "358833d6",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module networkx has no attribute kernighan_lin_bisection",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[0;32mIn [220]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mnx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkernighan_lin_bisection\u001b[49m(network)\n",
      "File \u001b[0;32m/opt/homebrew/anaconda3/lib/python3.9/site-packages/networkx/__init__.py:51\u001b[0m, in \u001b[0;36m__getattr__\u001b[0;34m(name)\u001b[0m\n\u001b[1;32m     42\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwrite_yaml\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m     43\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\n\u001b[1;32m     44\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mwrite_yaml has been removed from NetworkX, please use `yaml`\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m     45\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdirectly:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     49\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThis message will be removed in NetworkX 3.0.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m     50\u001b[0m     )\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodule \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m has no attribute \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mAttributeError\u001b[0m: module networkx has no attribute kernighan_lin_bisection"
     ]
    }
   ],
   "source": [
    "nx.kernighan_lin_bisection(network)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97d42ab1",
   "metadata": {},
   "outputs": [],
   "source": [
    "nx.lin"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
