{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c2734eb9-d9b9-43b2-a9fb-c25729a0f3a3",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-5fff5091c9d505d4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# 7. Programmierübung: Pandas & Seaborn\n",
    "\n",
    "<div style=\"display:flex;\">\n",
    "    <div style=\"text-align: left\">\n",
    "        Willkommen zur siebten Programmierübung Einführung in Python 3.\n",
    "    </div>\n",
    "    <img style=\"float: right; margin: 0px 15px 15px 0px\" src=\"https://www.python.org/static/img/python-logo-large.c36dccadd999.png?1576869008\" width=\"100\" />\n",
    "</div>\n",
    "\n",
    "Wenn Sie Fragen oder Verbesserungsvorschläge zum Inhalt oder Struktur der Notebooks haben, dann können sie eine E-Mail an Phil Keier ([p.keier@hbk-bs.de](mailto:p.keier@hbk-bs.de?subject=[SigSys]%20Feedback%20Programmierübung&amp)) oder Martin Le ([martin.le@tu-bs.de](mailto:martin.le@tu-bs.de?subject=[SigSys]%20Feedback%20Programmierübung&amp)) schreiben.\n",
    "\n",
    "Link zu einem Python Spickzettel: [hier](https://s3.amazonaws.com/assets.datacamp.com/blog_assets/PythonForDataScience.pdf)\n",
    "\n",
    "Der Großteil des Python-Tutorials stammt aus der Veranstaltung _Deep Learning Lab_ und von [www.python-kurs.eu](https://www.python-kurs.eu/python3_kurs.php) und wurde für _Signale und Systeme_, sowie _Einführung in die Programmierung für Nicht Informatiker_ angepasst.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8af16cfd-827f-4e7d-91a3-970e920ad212",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-fa7bc65ef436bf2f",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Was ist Pandas?\n",
    "\n",
    ">_pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real-world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open source data analysis/manipulation tool available in any language. It is already well on its way toward this goal._\n",
    "\n",
    "Pandas Keyfeature sind die beiden Datenstruckturen [Series](https://pandas.pydata.org/docs/reference/series.html) und [DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html#pandas.DataFrame).\n",
    "\n",
    "Diesem Notebook liegt zu Lernzwecken das Datenset `unis_nd.csv` bei, mit dem die Grundlegenden Funktionen Pandas gezeigt werden.\n",
    "\n",
    "__Für dieses Notebook schauen Sie bitte in die [Pandas Docs](https://pandas.pydata.org/docs/)!!!__ Dort sind alle Funktionen beschrieben die wir hier bearbeiten und noch mehr!\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "496ec5e1-2fdb-4075-853b-c91a6144ac82",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-7fc3ec9d80a10c43",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Was ist Seaborn?\n",
    "\n",
    ">_Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics._\n",
    "\n",
    "Seaborn bietet dabei keine neue Funktionalität gegenüber dem bekannten MatPlotLib, jedoch abstrahiert es Darstellungen die Aufwendig mit MatPlotLib darzustelln wären. Schaue dir daher gerne die [Gallerie](https://seaborn.pydata.org/examples/index.html) an.\n",
    "\n",
    "__Für dieses Notebook schauen Sie bitte in die [Searborn Docs](https://seaborn.pydata.org/api.html)!!!__ Dort sind alle Funktionen beschrieben die wir hier bearbeiten und noch mehr!\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62286603-158e-4448-98e5-e8f4aa60448a",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d7a24465d2b7b67c",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Achtung\n",
    "\n",
    "Falls es zu Problemen kommen sollte das Seaborn nicht bekannt sei führe bitte vor **jedem** bearbeiten folgende Zeile aus:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7198387d-3fcc-4501-9460-d07e84384a75",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-a2a83048f4c8f0b8",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting seaborn\n",
      "  Using cached seaborn-0.13.2-py3-none-any.whl.metadata (5.4 kB)\n",
      "Requirement already satisfied: numpy!=1.24.0,>=1.20 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from seaborn) (2.1.2)\n",
      "Collecting pandas>=1.2 (from seaborn)\n",
      "  Downloading pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (89 kB)\n",
      "Requirement already satisfied: matplotlib!=3.6.1,>=3.4 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from seaborn) (3.9.2)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.3.1)\n",
      "Requirement already satisfied: cycler>=0.10 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (0.12.1)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (4.54.1)\n",
      "Requirement already satisfied: kiwisolver>=1.3.1 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.4.7)\n",
      "Requirement already satisfied: packaging>=20.0 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (24.1)\n",
      "Requirement already satisfied: pillow>=8 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (11.0.0)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (3.2.0)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (2.9.0.post0)\n",
      "Collecting pytz>=2020.1 (from pandas>=1.2->seaborn)\n",
      "  Using cached pytz-2024.2-py2.py3-none-any.whl.metadata (22 kB)\n",
      "Collecting tzdata>=2022.7 (from pandas>=1.2->seaborn)\n",
      "  Downloading tzdata-2024.2-py2.py3-none-any.whl.metadata (1.4 kB)\n",
      "Requirement already satisfied: six>=1.5 in /home/phil/Desktop/programmieren_wise_24_25/Material/env/lib64/python3.12/site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.4->seaborn) (1.16.0)\n",
      "Using cached seaborn-0.13.2-py3-none-any.whl (294 kB)\n",
      "Downloading pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.7 MB)\n",
      "\u001b[2K   \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.7/12.7 MB\u001b[0m \u001b[31m21.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0mm eta \u001b[36m0:00:01\u001b[0m0:01\u001b[0m\n",
      "\u001b[?25hUsing cached pytz-2024.2-py2.py3-none-any.whl (508 kB)\n",
      "Downloading tzdata-2024.2-py2.py3-none-any.whl (346 kB)\n",
      "Installing collected packages: pytz, tzdata, pandas, seaborn\n",
      "Successfully installed pandas-2.2.3 pytz-2024.2 seaborn-0.13.2 tzdata-2024.2\n",
      "\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install seaborn"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c6fa552-7e9c-4561-b7c3-e72268db9afb",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-430939b1ccd3736f",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Import Pandas\n",
    "\n",
    "Pandas wird vom Internet mit der Abkürzung `pd` importiert.\n",
    "\n",
    "Führen Sie die nächste Zelle beim neustart des Notebooks bitte immer aus."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "64315664-4ab4-46db-9600-b0dd58f95174",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-44f74bf2f8803769",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ea5a1da-05f7-41a1-96cc-aaba1c74cf0d",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-53884904925c1212",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Data Frame\n",
    "\n",
    "Ein Pandas Data Frame `pd.DataFrame` ist eine 2-Dimensionale Datenstrucktur, vergleichbar mit einer Excel Tabelle.\n",
    "\n",
    "![](https://pandas.pydata.org/docs/_images/01_table_dataframe.svg)\n",
    "\n",
    "Um aus einem Dictionary einen Pandas DataFrame zu erstellen wird das Objekt `pd.DataFrame` verwendet. Dabei ist es wichtig das das Dicitionary einer Ordnung folgt, bei dem die Schlüssel die Namen der Spalten sind. Die Reihe im Data Frame wird dann einem Schlüssel als Liste mit Werten zugeordnet.\n",
    "\n",
    "Schauen Sie sich dazu Folgendes Dictionary an, welches ein Subset aus dem beiliegenden Datenset `unis_nd.csv`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "30d2f79a-3f54-4397-a1f3-626b58fdf67e",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-e30f1b0549eb4481",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "unis_data = {\n",
    "    \t\"University name\": [ \n",
    "            \"Hochschule für Bildende Künste Braunschweig\",\n",
    "            \"Technische Universität Carolo-Wilhelmina zu Braunschweig\",\n",
    "            \"Hochschule 21\",\n",
    "            \"Technische Universität Clausthal\",\n",
    "            \"Hochschule Emden/Leer\",\n",
    "            \"PFH – Private Hochschule Göttingen\",\n",
    "            \"Georg-August-Universität Göttingen\"\n",
    "        ],\n",
    "    \n",
    "        \"Type of university\": [\n",
    "            \"Artistic university\",\n",
    "            \"University\",\n",
    "            \"University of Applied Sciences\",\n",
    "            \"University\",\n",
    "            \"University of Applied Sciences\",\n",
    "            \"University of Applied Sciences\",\n",
    "            \"University\"\n",
    "        ]\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba23542f-9030-45a3-a7bc-9c3841ae843e",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-08a43ccd460568f5",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Um aus dem Dictionary ein DataFrame zu erstellen, wird es einfach als Input für `pd.DataFrame` verwendet.\n",
    "\n",
    "Anschließend lassen wir es ausgeben. Nehmen Sie sich gerne die Zeit uns inspizieren Sie die Strucktur des beispielhaften DataFrames:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "074d682c-e936-40c3-97e1-2208b4e86a79",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-b519f770ad46c82b",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "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>University name</th>\n",
       "      <th>Type of university</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Hochschule für Bildende Künste Braunschweig</td>\n",
       "      <td>Artistic university</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Technische Universität Carolo-Wilhelmina zu Br...</td>\n",
       "      <td>University</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hochschule 21</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Technische Universität Clausthal</td>\n",
       "      <td>University</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hochschule Emden/Leer</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>PFH – Private Hochschule Göttingen</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Georg-August-Universität Göttingen</td>\n",
       "      <td>University</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     University name  \\\n",
       "0        Hochschule für Bildende Künste Braunschweig   \n",
       "1  Technische Universität Carolo-Wilhelmina zu Br...   \n",
       "2                                      Hochschule 21   \n",
       "3                   Technische Universität Clausthal   \n",
       "4                              Hochschule Emden/Leer   \n",
       "5                 PFH – Private Hochschule Göttingen   \n",
       "6                 Georg-August-Universität Göttingen   \n",
       "\n",
       "               Type of university  \n",
       "0             Artistic university  \n",
       "1                      University  \n",
       "2  University of Applied Sciences  \n",
       "3                      University  \n",
       "4  University of Applied Sciences  \n",
       "5  University of Applied Sciences  \n",
       "6                      University  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis = pd.DataFrame(unis_data)\n",
    "unis"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e732d3ff-463e-4411-b023-47f2fe02e4c5",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-6ed4bfb85a3f95bb",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## Zugriffs Operationen\n",
    "\n",
    "Wie bereits vom Dicitonary bekannt lässt sich mittels Schlüssel (im Beispiel `University name`) auf eine Spalte zugreifen. Dabei ist wichtig zu erwähnen das jede Spalte in einem `DataFrame` eine `Series` ist. Eine `Series` ist dabei das 1-Dimensionale äquivalent zum 2-Dimensionales `DataFrame`.\n",
    "\n",
    "Im Folgenden Beispiel Selektieren wir die Series `University name` aus dem DataFrame `unis_nd`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cfa48421-7e56-4c10-a4fc-3d907f429309",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-ef292cd51db1030b",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          Hochschule für Bildende Künste Braunschweig\n",
       "1    Technische Universität Carolo-Wilhelmina zu Br...\n",
       "2                                        Hochschule 21\n",
       "3                     Technische Universität Clausthal\n",
       "4                                Hochschule Emden/Leer\n",
       "5                   PFH – Private Hochschule Göttingen\n",
       "6                   Georg-August-Universität Göttingen\n",
       "Name: University name, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis[\"University name\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62a92dad-506a-434f-b343-c020f89b19a1",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-dfdff5bf7e9be2ad",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Um eine `Series` manuel zu definieren wird `pd.Series` verwendet. Dabei kann mittels Parameter `name` ein label für die Series gesetzt werden:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7d54c159-119d-4350-9cf9-081ecc8f5712",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-2a1d8c078f0249d8",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          Hochschule für Bildende Künste Braunschweig\n",
       "1    Technische Universität Carolo-Wilhelmina zu Br...\n",
       "2                                        Hochschule 21\n",
       "3                     Technische Universität Clausthal\n",
       "4                                Hochschule Emden/Leer\n",
       "5                   PFH – Private Hochschule Göttingen\n",
       "6                   Georg-August-Universität Göttingen\n",
       "Name: University name, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "uni_names = pd.Series([ \n",
    "            \"Hochschule für Bildende Künste Braunschweig\",\n",
    "            \"Technische Universität Carolo-Wilhelmina zu Braunschweig\",\n",
    "            \"Hochschule 21\",\n",
    "            \"Technische Universität Clausthal\",\n",
    "            \"Hochschule Emden/Leer\",\n",
    "            \"PFH – Private Hochschule Göttingen\",\n",
    "            \"Georg-August-Universität Göttingen\"\n",
    "        ], name=\"University name\")\n",
    "\n",
    "uni_names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97930782-3e33-4036-8be2-f40c10f18794",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-e989fac8445abfe4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Wie Sie sehen ist der Output identisch.\n",
    "\n",
    "Um auf einzelne Elemente in der `Series` zuzugreifen werden, wie bereits bekannt von Listen, Index zugriffe verwendet.\n",
    "\n",
    "Beispiel; Selektion des 2 Elementes:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3947baa1-1a3d-41fa-866d-a8acbd07a89a",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-07bcadf8f88e6603",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Technische Universität Carolo-Wilhelmina zu Braunschweig'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "uni_names[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8541372-36fa-4f59-b131-9c737b1e3457",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-0662b5716d2ffbf6",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Analog dazu für den Data Frame. Bei dem zuerst die Spalte und dann Reihe selektiert wird:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "69e57b94-06ea-445b-a8ae-63952dd95358",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d17cf7e2161c24e3",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Technische Universität Carolo-Wilhelmina zu Braunschweig'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis[\"University name\"][1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "720262aa-1d99-469b-896e-1bf5da4b712b",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-a5f5d2b918c6704b",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Wie beim Dictionary lassen sich auch die bekannten Funktionen `.values`, `.keys` & `.items` ausgeben.\n",
    "\n",
    "Beispiel `.keys`:\n",
    "\n",
    "Achtung die Ausgabe ist keine Liste auch wenn es den Anschein erwirkt!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "84809ffa-64a2-4c9d-b3b1-3ff792ebda86",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-0a4876a0ab9f0672",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Schlüssel:\n",
      "Index(['University name', 'Type of university'], dtype='object')\n",
      "\n",
      "Rückgabetype:\n",
      "<class 'pandas.core.indexes.base.Index'>\n"
     ]
    }
   ],
   "source": [
    "print(\"Schlüssel:\", unis.keys(), \"\\nRückgabetype:\", type(unis.keys()), sep='\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88957f18-bbc0-4ce3-981d-9b6735ea437b",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-7708becc41b11601",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## Aufgabe - Erstellen eines Dataframes\n",
    "\n",
    "*5 Punkte*\n",
    "\n",
    "Erstellen Sie einen Pandas Data Frame mit dem namen `uni_addr`, nachdem Schema folgender Tabelle:\n",
    "\n",
    "| Address                  | plz                        |\n",
    "|--------------------------|----------------------------|\n",
    "| Johannes-Selenka-Platz 1 | 38118 Braunschweig         |\n",
    "| Universitätspl. 2        | 38106 Braunschweig         |\n",
    "| Harburger Str. 6         | 21614 Buxtehude            |\n",
    "| Adolph-Roemer-Straße 2A  | 38678 Clausthal-Zellerfeld |\n",
    "| Constantiapl. 4          | 26723 Emden                |\n",
    "| Weender Landstraße 3-7   | 37073 Göttingen            |\n",
    "| Wilhelmsplatz 1          | 37073 Göttingen            |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2a6555ac-97ce-4d78-8d19-359b1eeb5a1a",
   "metadata": {
    "editable": true,
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-6ea306cdf2a57ea3",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "uni_addr = None\n",
    "\n",
    "### BEGIN SOLUTION\n",
    "uni_addr = pd.DataFrame({\n",
    "    \"Address\": [\"Johannes-Selenka-Platz 1\", \"Universitätspl. 2\", \"Harburger Str. 6\", \"Adolph-Roemer-Straße 2A\", \"Constantiapl. 4\", \"Weender Landstraße 3-7\", \"Wilhelmsplatz 1\"],\n",
    "    \"plz\": [\"38118 Braunschweig\", \"38106 Braunschweig\", \"21614 Buxtehude\", \"38678 Clausthal-Zellerfeld\", \"26723 Emden\", \"37073 Göttingen\", \"37073 Göttingen\",]\n",
    "})\n",
    "### END SOLUTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1936705b-949b-47ad-95e1-67d987662efc",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-daa317b892c6c606",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Hier werden ihre Lösung gestestet ...\n",
    "assert isinstance(uni_addr, pd.DataFrame)\n",
    "assert len(uni_addr[\"Address\"]) == 7\n",
    "assert len(uni_addr[\"plz\"]) == 7\n",
    "### BEGIN HIDDEN TESTS\n",
    "uni_addr_test = pd.DataFrame({\n",
    "    \"Address\": [\"Johannes-Selenka-Platz 1\", \"Universitätspl. 2\", \"Harburger Str. 6\", \"Adolph-Roemer-Straße 2A\", \"Constantiapl. 4\", \"Weender Landstraße 3-7\", \"Wilhelmsplatz 1\"],\n",
    "    \"plz\": [\"38118 Braunschweig\", \"38106 Braunschweig\", \"21614 Buxtehude\", \"38678 Clausthal-Zellerfeld\", \"26723 Emden\", \"37073 Göttingen\", \"37073 Göttingen\",]\n",
    "})\n",
    "\n",
    "for el1, el2 in zip(uni_addr[\"Address\"], uni_addr_test[\"Address\"]):\n",
    "    assert el1 == el2\n",
    "\n",
    "for el1, el2 in zip(uni_addr[\"plz\"], uni_addr_test[\"plz\"]):\n",
    "    assert el1 == el2\n",
    "\n",
    "### END HIDDEN TESTS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f25a6fb-3f9b-497a-a966-3e53c2f86b9c",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-8871c67f03f141dd",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Aufgabe - Extrahieren einer Series\n",
    "\n",
    "*1 Punkte*\n",
    "\n",
    "Exthahieren Sie die Series `plz` aus dem zuvor erstelltem Data Frame `uni_addr` und speichern Sie ihr Ergebnis in `uni_plz`.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2de2487d-158e-4dec-a5fa-ccd7478c161c",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-240ce62f624ce706",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "uni_plz = None\n",
    "\n",
    "### BEGIN SOLUTION\n",
    "uni_plz = uni_addr[\"plz\"]\n",
    "### END SOLUTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "613f9082-d963-4129-a70c-acfab56759e0",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-dbd86892a80c1f08",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0            38118 Braunschweig\n",
      "1            38106 Braunschweig\n",
      "2               21614 Buxtehude\n",
      "3    38678 Clausthal-Zellerfeld\n",
      "4                   26723 Emden\n",
      "5               37073 Göttingen\n",
      "6               37073 Göttingen\n",
      "Name: plz, dtype: object\n"
     ]
    }
   ],
   "source": [
    "# Hier werden ihre Lösungen getestet\n",
    "print(uni_plz)\n",
    "assert isinstance(uni_plz, pd.Series)\n",
    "### BEGIN HIDDEN TESTS\n",
    "uni_plz_test = pd.Series([\"38118 Braunschweig\", \"38106 Braunschweig\", \"21614 Buxtehude\", \"38678 Clausthal-Zellerfeld\", \"26723 Emden\", \"37073 Göttingen\", \"37073 Göttingen\",], name=\"plz\")\n",
    "for el1, el2 in zip(uni_plz, uni_plz_test):\n",
    "    assert el1 == el2\n",
    "### END HIDDEN TESTS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f308563d-e961-40a8-bf11-79d137b02e88",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-02f5ee7a60d555b6",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Reading Data\n",
    "\n",
    "Die unweiten des Internets ermöglichen es uns Daten auf die unterschiedlichsten Arten zu Archivieren. \n",
    "\n",
    "Für die Speicherung und Darstellung von (Roh-)Daten werden Datenbanken ([SQL](https://en.wikipedia.org/wiki/SQL)), Transportformate ([JSON](https://en.wikipedia.org/wiki/JSON), [XML](https://en.wikipedia.org/wiki/XML)), Tabellenformate ([Excel](https://en.wikipedia.org/wiki/Microsoft_Excel), [CSV](https://en.wikipedia.org/wiki/Comma-separated_values)) und noch viele mehr verwendet.\n",
    "\n",
    "Ein beliebtes Betriebsystemunabhängiges Dateiformat für kleine Datensätze (bis 10GB) werden `.csv` Dateien verwendet. Jedes gängige Tabellenkalkulations- und Umfragentool kann seine Daten als _Comma-seperated values_ kurz _CSV_ Exportieren. Schauen Sie dazu gerne in das Datenset `unis_nd.csv`. Im folgenden wird sich ausschließlich auf das Einlesen von CSV-Dateien bezogen. Welche Funktionen und Dateienformate Pandas unterstüzt entnehmen Sie bitte der Dokumentation zu [input/output](https://pandas.pydata.org/docs/reference/io.html).\n",
    "\n",
    "Da ich ihnen Die Spannung nicht nehmen möchte lösen Sie für die folgenden Beispiele bitte nächste Aufgabe."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6d7e62b-df8e-4da5-8f74-6c81be0f00df",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-7bf6c58e48e58743",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Aufgabe - Read CSV\n",
    "\n",
    "*1 Punkt*\n",
    "\n",
    "Nutzen sie die Funktion `pd.read_csv` um das Datenset `unis_nd.csv` in die Variable `unis_nd` einzulesen.\n",
    "\n",
    "Falls Sie hilfe benötigen lesen Sie gerne die Dokumentation im [Getting Started](https://pandas.pydata.org/docs/getting_started/intro_tutorials/02_read_write.html) Guide.\n",
    "\n",
    "_Hinweis: Die Datei liegt in keinem Ordner, sondern im selben wie dieses Notebook!_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b08cc0c4-277b-4e9f-b6e7-a607b912febe",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3cdc8afd6dc12d44",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "unis_nd = None\n",
    "\n",
    "### BEGIN SOLUTION\n",
    "unis_nd = pd.read_csv(\"unis_nd.csv\")\n",
    "### END SOLUTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e5760557-ddec-4502-b2d3-e8cc2ef70348",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-fd974b3aa3563ca0",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Hier werden ihre Lösungen getestet\n",
    "assert isinstance(unis_nd, pd.DataFrame)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffcf5c5c-1e35-42f9-b35b-2494ff4c421f",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-614d1dc9c4566861",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Ausgabe Operationen\n",
    "\n",
    "Um den gesamten Data Frame auszugeben nutzen Sie einfach die Syntax aus nächster Zelle.\n",
    "\n",
    "Achtung die Ausgabe ist vergleichweise Groß! Nehmen Sie sich gerne Zeit und schauen Sie sich das Dataset an."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c9b8b9a0-0a62-4887-b6e8-c1da6086d7e4",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-ec7681e1a54af790",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "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>University name</th>\n",
       "      <th>Type of university</th>\n",
       "      <th>Sponsorship</th>\n",
       "      <th>Right of promotion</th>\n",
       "      <th>Founding year</th>\n",
       "      <th>Number of students</th>\n",
       "      <th>Address</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>plz</th>\n",
       "      <th>pic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Hochschule für Bildende Künste Braunschweig</td>\n",
       "      <td>Artistic university</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1963</td>\n",
       "      <td>976.000</td>\n",
       "      <td>Johannes-Selenka-Platz 1</td>\n",
       "      <td>52.257738</td>\n",
       "      <td>10.502315</td>\n",
       "      <td>38118 Braunschweig</td>\n",
       "      <td>https://www.hbk-bs.de/fileadmin/_processed_/5/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Technische Universität Carolo-Wilhelmina zu Br...</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1745</td>\n",
       "      <td>17709.000</td>\n",
       "      <td>Universitätspl. 2</td>\n",
       "      <td>52.273550</td>\n",
       "      <td>10.530097</td>\n",
       "      <td>38106 Braunschweig</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hochschule 21</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>2005</td>\n",
       "      <td>1084.000</td>\n",
       "      <td>Harburger Str. 6</td>\n",
       "      <td>53.477650</td>\n",
       "      <td>9.704650</td>\n",
       "      <td>21614 Buxtehude</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Technische Universität Clausthal</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1775</td>\n",
       "      <td>3446.000</td>\n",
       "      <td>Adolph-Roemer-Straße 2A</td>\n",
       "      <td>51.804840</td>\n",
       "      <td>10.334110</td>\n",
       "      <td>38678 Clausthal-Zellerfeld</td>\n",
       "      <td>https://www.presse.tu-clausthal.de/fileadmin/T...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hochschule Emden/Leer</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2009</td>\n",
       "      <td>4481.000</td>\n",
       "      <td>Constantiapl. 4</td>\n",
       "      <td>53.368160</td>\n",
       "      <td>7.181410</td>\n",
       "      <td>26723 Emden</td>\n",
       "      <td>https://sta-hisweb.hs-emden-leer.de/QIS/images...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>PFH – Private Hochschule Göttingen</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1995</td>\n",
       "      <td>4226.000</td>\n",
       "      <td>Weender Landstraße 3-7</td>\n",
       "      <td>51.538910</td>\n",
       "      <td>9.933220</td>\n",
       "      <td>37073 Göttingen</td>\n",
       "      <td>https://goettingen-campus.de/fileadmin/_proces...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Georg-August-Universität Göttingen</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1737</td>\n",
       "      <td>28614.000</td>\n",
       "      <td>Wilhelmsplatz 1</td>\n",
       "      <td>51.534070</td>\n",
       "      <td>9.937850</td>\n",
       "      <td>37073 Göttingen</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Fachhochschule für die Wirtschaft Hannover</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1996</td>\n",
       "      <td>641.000</td>\n",
       "      <td>Freundallee 15</td>\n",
       "      <td>52.366200</td>\n",
       "      <td>9.772470</td>\n",
       "      <td>30173 Hannover</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Hochschule Hannover</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>9209.000</td>\n",
       "      <td>Ricklinger Stadtweg 120</td>\n",
       "      <td>52.354190</td>\n",
       "      <td>9.722380</td>\n",
       "      <td>30459 Hannover</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Hochschule für Musik, Theater und Medien Hannover</td>\n",
       "      <td>Artistic university</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1897</td>\n",
       "      <td>1409.000</td>\n",
       "      <td>Neues Haus 1</td>\n",
       "      <td>52.377380</td>\n",
       "      <td>9.753920</td>\n",
       "      <td>30175 Hannover</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Leibniz-Fachhochschule</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1920</td>\n",
       "      <td>589.000</td>\n",
       "      <td>Expo Plaza 11</td>\n",
       "      <td>52.321150</td>\n",
       "      <td>9.818680</td>\n",
       "      <td>30539 Hannover</td>\n",
       "      <td>https://www.visit-hannover.com/var/storage/ima...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Medizinische Hochschule Hannover (MHH)</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1963</td>\n",
       "      <td>3778.000</td>\n",
       "      <td>Carl-Neuberg-Straße 1</td>\n",
       "      <td>52.384050</td>\n",
       "      <td>9.806030</td>\n",
       "      <td>30625 Hannover</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Stiftung Tierärztliche Hochschule Hannover</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1778</td>\n",
       "      <td>2381.000</td>\n",
       "      <td>Bünteweg 2</td>\n",
       "      <td>52.354680</td>\n",
       "      <td>9.797730</td>\n",
       "      <td>30559 Hannover</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/de/thum...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Gottfried Wilhelm Leibniz Universität Hannover</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1831</td>\n",
       "      <td>28935.000</td>\n",
       "      <td>Welfengarten 1</td>\n",
       "      <td>52.382250</td>\n",
       "      <td>9.717770</td>\n",
       "      <td>30167 Hannover</td>\n",
       "      <td>https://www.uni-hannover.de/fileadmin/_process...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Fachhochschule für Interkulturelle Theologie H...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>2012</td>\n",
       "      <td>91.000</td>\n",
       "      <td>Missionsstraße 3-5</td>\n",
       "      <td>52.708843</td>\n",
       "      <td>10.140710</td>\n",
       "      <td>29320 Südheide</td>\n",
       "      <td>https://cdn.max-e5.info/damfiles/logo/fh_herma...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Universität Hildesheim</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1978</td>\n",
       "      <td>8378.000</td>\n",
       "      <td>Universitätspl. 1</td>\n",
       "      <td>52.134010</td>\n",
       "      <td>9.974690</td>\n",
       "      <td>31141 Hildesheim</td>\n",
       "      <td>https://www.uni-hildesheim.de/media/_processed...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>HAWK Hochschule für angewandte Wissenschaft un...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>6495.000</td>\n",
       "      <td>Hohnsen 4</td>\n",
       "      <td>52.142460</td>\n",
       "      <td>9.957980</td>\n",
       "      <td>31134 Hildesheim</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>HAWK Hochschule für angewandte Wissenschaft un...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>6495.000</td>\n",
       "      <td>Haarmannpl. 3</td>\n",
       "      <td>51.827260</td>\n",
       "      <td>9.450690</td>\n",
       "      <td>37603 Holzminden</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>HAWK Hochschule für angewandte Wissenschaft un...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>6495.000</td>\n",
       "      <td>Von-Ossietzky-Straße 99</td>\n",
       "      <td>51.521750</td>\n",
       "      <td>9.969670</td>\n",
       "      <td>37085 Göttingen</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Leuphana Universität Lüneburg</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1946</td>\n",
       "      <td>6497.000</td>\n",
       "      <td>Universitätsallee 1</td>\n",
       "      <td>53.228531</td>\n",
       "      <td>10.401710</td>\n",
       "      <td>21335 Lüneburg</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Norddeutsche Hochschule für Rechtspflege – Nie...</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2007</td>\n",
       "      <td>6409.000</td>\n",
       "      <td>Godehardspl. 6</td>\n",
       "      <td>52.144840</td>\n",
       "      <td>9.949230</td>\n",
       "      <td>31134 Hildesheim</td>\n",
       "      <td>https://static.studycheck.de/media/images/inst...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Kommunale Hochschule für Verwaltung in Nieders...</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2007</td>\n",
       "      <td>1570.000</td>\n",
       "      <td>Wielandstraße 8</td>\n",
       "      <td>52.370500</td>\n",
       "      <td>9.722390</td>\n",
       "      <td>30169 Hannover</td>\n",
       "      <td>https://www.nsi-hsvn.de/fileadmin/user_upload/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Carl von Ossietzky Universität Oldenburg\\n</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1973</td>\n",
       "      <td>15635.000</td>\n",
       "      <td>Uhlhornsweg 49-55</td>\n",
       "      <td>53.147340</td>\n",
       "      <td>8.179020</td>\n",
       "      <td>26129 Oldenburg</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>Hochschule Osnabrück</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>13620.000</td>\n",
       "      <td>Albrechtstraße 30</td>\n",
       "      <td>52.282680</td>\n",
       "      <td>8.025010</td>\n",
       "      <td>49076 Osnabrück</td>\n",
       "      <td>https://login.hs-osnabrueck.de/nidp/hsos/image...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>Universität Osnabrück</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1973</td>\n",
       "      <td>13640.000</td>\n",
       "      <td>Neuer Graben 29</td>\n",
       "      <td>52.271370</td>\n",
       "      <td>8.044540</td>\n",
       "      <td>49074 Osnabrück</td>\n",
       "      <td>https://www.eh-tabor.de/sites/default/files/st...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>Hochschule Braunschweig/Wolfenbüttel, Ostfalia...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>11577.000</td>\n",
       "      <td>Salzdahlumer Str. 46/48</td>\n",
       "      <td>52.176830</td>\n",
       "      <td>10.548650</td>\n",
       "      <td>38302 Wolfenbüttel</td>\n",
       "      <td>https://www.ostfalia.de/export/system/modules/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Hochschule Wolfsburg, Ostfalia Hochschule für ...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>11577.000</td>\n",
       "      <td>Robert-Koch-Platz 8A</td>\n",
       "      <td>52.425950</td>\n",
       "      <td>10.787110</td>\n",
       "      <td>38440 Wolfsburg</td>\n",
       "      <td>https://www.ostfalia.de/export/system/modules/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Hochschule Suderburg, Ostfalia Hochschule für ...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>11577.000</td>\n",
       "      <td>Herbert-Meyer-Straße 7</td>\n",
       "      <td>52.897610</td>\n",
       "      <td>10.446590</td>\n",
       "      <td>29556 Suderburg</td>\n",
       "      <td>https://www.ostfalia.de/export/system/modules/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>Hochschule Salzgitter, Ostfalia Hochschule für...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>1971</td>\n",
       "      <td>11577.000</td>\n",
       "      <td>Karl-Scharfenberg-Straße 55/57</td>\n",
       "      <td>52.087240</td>\n",
       "      <td>10.380550</td>\n",
       "      <td>38229 Salzgitter</td>\n",
       "      <td>https://www.ostfalia.de/export/system/modules/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>Hochschule für Künste im Sozialen, Ottersberg</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1967</td>\n",
       "      <td>342.000</td>\n",
       "      <td>Große Str. 107</td>\n",
       "      <td>53.106680</td>\n",
       "      <td>9.163100</td>\n",
       "      <td>28870 Ottersberg</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>Private Hochschule für Wirtschaft und Technik ...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1998</td>\n",
       "      <td>558.000</td>\n",
       "      <td>Rombergstraße 40</td>\n",
       "      <td>52.721250</td>\n",
       "      <td>8.278910</td>\n",
       "      <td>49377 Vechta</td>\n",
       "      <td>https://www.phwt.de/wp-content/uploads/2020/09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>Private Hochschule für Wirtschaft und Technik ...</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>1998</td>\n",
       "      <td>558.000</td>\n",
       "      <td>Schlesier Str. 13A</td>\n",
       "      <td>52.611710</td>\n",
       "      <td>8.363340</td>\n",
       "      <td>49356 Diepholz</td>\n",
       "      <td>https://www.phwt.de/wp-content/uploads/2020/09...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>Universität Vechta</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1995</td>\n",
       "      <td>4.551</td>\n",
       "      <td>Driverstraße 22</td>\n",
       "      <td>52.721170</td>\n",
       "      <td>8.293800</td>\n",
       "      <td>49377 Vechta</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>Hochschule Weserbergland</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>2010</td>\n",
       "      <td>485.000</td>\n",
       "      <td>Am Stockhof 2</td>\n",
       "      <td>52.098750</td>\n",
       "      <td>9.355420</td>\n",
       "      <td>31785 Hameln</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>Jade Hochschule – Wilhelmshaven</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2009</td>\n",
       "      <td>6789.000</td>\n",
       "      <td>Friedrich-Paffrath-Straße 101</td>\n",
       "      <td>53.547870</td>\n",
       "      <td>8.088040</td>\n",
       "      <td>26389 Wilhelmshaven</td>\n",
       "      <td>https://www.jade-hs.de/fileadmin/layout2016/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>Jade Hochschule – Oldenburg</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2009</td>\n",
       "      <td>6789.000</td>\n",
       "      <td>Ofener Str. 16/19</td>\n",
       "      <td>53.141790</td>\n",
       "      <td>8.202130</td>\n",
       "      <td>26121 Oldenburg</td>\n",
       "      <td>https://www.jade-hs.de/fileadmin/layout2016/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Jade Hochschule – Elsfleth</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2009</td>\n",
       "      <td>6789.000</td>\n",
       "      <td>Weserstraße 52</td>\n",
       "      <td>53.242440</td>\n",
       "      <td>8.466510</td>\n",
       "      <td>26931 Elsfleth</td>\n",
       "      <td>https://www.jade-hs.de/fileadmin/layout2016/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>Steuerakademie Niedersachsen Rinteln</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2006</td>\n",
       "      <td>500.000</td>\n",
       "      <td>Wilhelm-Busch-Weg 29</td>\n",
       "      <td>52.206960</td>\n",
       "      <td>9.091120</td>\n",
       "      <td>31737 Rinteln</td>\n",
       "      <td>https://www.steuerakademie.niedersachsen.de/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Steuerakademie Niedersachsen Bad Eilsen</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2006</td>\n",
       "      <td>500.000</td>\n",
       "      <td>Bahnhofstraße 5</td>\n",
       "      <td>52.239810</td>\n",
       "      <td>9.104230</td>\n",
       "      <td>31707 Bad Eilsen</td>\n",
       "      <td>https://www.steuerakademie.niedersachsen.de/as...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      University name  \\\n",
       "0         Hochschule für Bildende Künste Braunschweig   \n",
       "1   Technische Universität Carolo-Wilhelmina zu Br...   \n",
       "2                                       Hochschule 21   \n",
       "3                    Technische Universität Clausthal   \n",
       "4                               Hochschule Emden/Leer   \n",
       "5                  PFH – Private Hochschule Göttingen   \n",
       "6                  Georg-August-Universität Göttingen   \n",
       "7          Fachhochschule für die Wirtschaft Hannover   \n",
       "8                                 Hochschule Hannover   \n",
       "9   Hochschule für Musik, Theater und Medien Hannover   \n",
       "10                             Leibniz-Fachhochschule   \n",
       "11             Medizinische Hochschule Hannover (MHH)   \n",
       "12         Stiftung Tierärztliche Hochschule Hannover   \n",
       "13     Gottfried Wilhelm Leibniz Universität Hannover   \n",
       "14  Fachhochschule für Interkulturelle Theologie H...   \n",
       "15                             Universität Hildesheim   \n",
       "16  HAWK Hochschule für angewandte Wissenschaft un...   \n",
       "17  HAWK Hochschule für angewandte Wissenschaft un...   \n",
       "18  HAWK Hochschule für angewandte Wissenschaft un...   \n",
       "19                      Leuphana Universität Lüneburg   \n",
       "20  Norddeutsche Hochschule für Rechtspflege – Nie...   \n",
       "21  Kommunale Hochschule für Verwaltung in Nieders...   \n",
       "22         Carl von Ossietzky Universität Oldenburg\\n   \n",
       "23                               Hochschule Osnabrück   \n",
       "24                              Universität Osnabrück   \n",
       "25  Hochschule Braunschweig/Wolfenbüttel, Ostfalia...   \n",
       "26  Hochschule Wolfsburg, Ostfalia Hochschule für ...   \n",
       "27  Hochschule Suderburg, Ostfalia Hochschule für ...   \n",
       "28  Hochschule Salzgitter, Ostfalia Hochschule für...   \n",
       "29      Hochschule für Künste im Sozialen, Ottersberg   \n",
       "30  Private Hochschule für Wirtschaft und Technik ...   \n",
       "31  Private Hochschule für Wirtschaft und Technik ...   \n",
       "32                                 Universität Vechta   \n",
       "33                           Hochschule Weserbergland   \n",
       "34                    Jade Hochschule – Wilhelmshaven   \n",
       "35                        Jade Hochschule – Oldenburg   \n",
       "36                         Jade Hochschule – Elsfleth   \n",
       "37               Steuerakademie Niedersachsen Rinteln   \n",
       "38            Steuerakademie Niedersachsen Bad Eilsen   \n",
       "\n",
       "                Type of university Sponsorship Right of promotion  \\\n",
       "0              Artistic university      public                yes   \n",
       "1                       University      public                yes   \n",
       "2   University of Applied Sciences      privat                 no   \n",
       "3                       University      public                yes   \n",
       "4   University of Applied Sciences      public                 no   \n",
       "5   University of Applied Sciences      privat                 no   \n",
       "6                       University      public                yes   \n",
       "7   University of Applied Sciences      privat                 no   \n",
       "8   University of Applied Sciences      public                 no   \n",
       "9              Artistic university      public                yes   \n",
       "10  University of Applied Sciences      privat                 no   \n",
       "11                      University      public                yes   \n",
       "12                      University      public                yes   \n",
       "13                      University      public                yes   \n",
       "14  University of Applied Sciences      privat                 no   \n",
       "15                      University      public                yes   \n",
       "16  University of Applied Sciences      public                 no   \n",
       "17  University of Applied Sciences      public                 no   \n",
       "18  University of Applied Sciences      public                 no   \n",
       "19                      University      public                yes   \n",
       "20    University of Administration      public                 no   \n",
       "21    University of Administration      public                 no   \n",
       "22                      University      public                yes   \n",
       "23  University of Applied Sciences      public                 no   \n",
       "24                      University      public                yes   \n",
       "25  University of Applied Sciences      public                 no   \n",
       "26  University of Applied Sciences      public                 no   \n",
       "27  University of Applied Sciences      public                 no   \n",
       "28  University of Applied Sciences      public                 no   \n",
       "29  University of Applied Sciences      privat                 no   \n",
       "30  University of Applied Sciences      privat                 no   \n",
       "31  University of Applied Sciences      privat                 no   \n",
       "32                      University      public                yes   \n",
       "33  University of Applied Sciences      privat                 no   \n",
       "34  University of Applied Sciences      public                 no   \n",
       "35  University of Applied Sciences      public                 no   \n",
       "36  University of Applied Sciences      public                 no   \n",
       "37    University of Administration      public                 no   \n",
       "38    University of Administration      public                 no   \n",
       "\n",
       "    Founding year  Number of students                         Address  \\\n",
       "0            1963             976.000        Johannes-Selenka-Platz 1   \n",
       "1            1745           17709.000               Universitätspl. 2   \n",
       "2            2005            1084.000                Harburger Str. 6   \n",
       "3            1775            3446.000         Adolph-Roemer-Straße 2A   \n",
       "4            2009            4481.000                 Constantiapl. 4   \n",
       "5            1995            4226.000          Weender Landstraße 3-7   \n",
       "6            1737           28614.000                 Wilhelmsplatz 1   \n",
       "7            1996             641.000                  Freundallee 15   \n",
       "8            1971            9209.000         Ricklinger Stadtweg 120   \n",
       "9            1897            1409.000                    Neues Haus 1   \n",
       "10           1920             589.000                   Expo Plaza 11   \n",
       "11           1963            3778.000           Carl-Neuberg-Straße 1   \n",
       "12           1778            2381.000                      Bünteweg 2   \n",
       "13           1831           28935.000                  Welfengarten 1   \n",
       "14           2012              91.000              Missionsstraße 3-5   \n",
       "15           1978            8378.000               Universitätspl. 1   \n",
       "16           1971            6495.000                       Hohnsen 4   \n",
       "17           1971            6495.000                   Haarmannpl. 3   \n",
       "18           1971            6495.000         Von-Ossietzky-Straße 99   \n",
       "19           1946            6497.000             Universitätsallee 1   \n",
       "20           2007            6409.000                  Godehardspl. 6   \n",
       "21           2007            1570.000                 Wielandstraße 8   \n",
       "22           1973           15635.000               Uhlhornsweg 49-55   \n",
       "23           1971           13620.000               Albrechtstraße 30   \n",
       "24           1973           13640.000                 Neuer Graben 29   \n",
       "25           1971           11577.000         Salzdahlumer Str. 46/48   \n",
       "26           1971           11577.000            Robert-Koch-Platz 8A   \n",
       "27           1971           11577.000          Herbert-Meyer-Straße 7   \n",
       "28           1971           11577.000  Karl-Scharfenberg-Straße 55/57   \n",
       "29           1967             342.000                  Große Str. 107   \n",
       "30           1998             558.000                Rombergstraße 40   \n",
       "31           1998             558.000              Schlesier Str. 13A   \n",
       "32           1995               4.551                 Driverstraße 22   \n",
       "33           2010             485.000                   Am Stockhof 2   \n",
       "34           2009            6789.000   Friedrich-Paffrath-Straße 101   \n",
       "35           2009            6789.000               Ofener Str. 16/19   \n",
       "36           2009            6789.000                  Weserstraße 52   \n",
       "37           2006             500.000            Wilhelm-Busch-Weg 29   \n",
       "38           2006             500.000                 Bahnhofstraße 5   \n",
       "\n",
       "          lat        lon                         plz  \\\n",
       "0   52.257738  10.502315          38118 Braunschweig   \n",
       "1   52.273550  10.530097          38106 Braunschweig   \n",
       "2   53.477650   9.704650             21614 Buxtehude   \n",
       "3   51.804840  10.334110  38678 Clausthal-Zellerfeld   \n",
       "4   53.368160   7.181410                 26723 Emden   \n",
       "5   51.538910   9.933220             37073 Göttingen   \n",
       "6   51.534070   9.937850             37073 Göttingen   \n",
       "7   52.366200   9.772470              30173 Hannover   \n",
       "8   52.354190   9.722380              30459 Hannover   \n",
       "9   52.377380   9.753920              30175 Hannover   \n",
       "10  52.321150   9.818680              30539 Hannover   \n",
       "11  52.384050   9.806030              30625 Hannover   \n",
       "12  52.354680   9.797730              30559 Hannover   \n",
       "13  52.382250   9.717770              30167 Hannover   \n",
       "14  52.708843  10.140710              29320 Südheide   \n",
       "15  52.134010   9.974690            31141 Hildesheim   \n",
       "16  52.142460   9.957980            31134 Hildesheim   \n",
       "17  51.827260   9.450690            37603 Holzminden   \n",
       "18  51.521750   9.969670             37085 Göttingen   \n",
       "19  53.228531  10.401710              21335 Lüneburg   \n",
       "20  52.144840   9.949230            31134 Hildesheim   \n",
       "21  52.370500   9.722390              30169 Hannover   \n",
       "22  53.147340   8.179020             26129 Oldenburg   \n",
       "23  52.282680   8.025010             49076 Osnabrück   \n",
       "24  52.271370   8.044540             49074 Osnabrück   \n",
       "25  52.176830  10.548650          38302 Wolfenbüttel   \n",
       "26  52.425950  10.787110             38440 Wolfsburg   \n",
       "27  52.897610  10.446590             29556 Suderburg   \n",
       "28  52.087240  10.380550            38229 Salzgitter   \n",
       "29  53.106680   9.163100            28870 Ottersberg   \n",
       "30  52.721250   8.278910                49377 Vechta   \n",
       "31  52.611710   8.363340              49356 Diepholz   \n",
       "32  52.721170   8.293800                49377 Vechta   \n",
       "33  52.098750   9.355420                31785 Hameln   \n",
       "34  53.547870   8.088040         26389 Wilhelmshaven   \n",
       "35  53.141790   8.202130             26121 Oldenburg   \n",
       "36  53.242440   8.466510              26931 Elsfleth   \n",
       "37  52.206960   9.091120               31737 Rinteln   \n",
       "38  52.239810   9.104230            31707 Bad Eilsen   \n",
       "\n",
       "                                                  pic  \n",
       "0   https://www.hbk-bs.de/fileadmin/_processed_/5/...  \n",
       "1   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "2   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "3   https://www.presse.tu-clausthal.de/fileadmin/T...  \n",
       "4   https://sta-hisweb.hs-emden-leer.de/QIS/images...  \n",
       "5   https://goettingen-campus.de/fileadmin/_proces...  \n",
       "6   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "7   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "8   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "9   https://upload.wikimedia.org/wikipedia/commons...  \n",
       "10  https://www.visit-hannover.com/var/storage/ima...  \n",
       "11  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "12  https://upload.wikimedia.org/wikipedia/de/thum...  \n",
       "13  https://www.uni-hannover.de/fileadmin/_process...  \n",
       "14  https://cdn.max-e5.info/damfiles/logo/fh_herma...  \n",
       "15  https://www.uni-hildesheim.de/media/_processed...  \n",
       "16  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "17  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "18  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "19  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "20  https://static.studycheck.de/media/images/inst...  \n",
       "21  https://www.nsi-hsvn.de/fileadmin/user_upload/...  \n",
       "22  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "23  https://login.hs-osnabrueck.de/nidp/hsos/image...  \n",
       "24  https://www.eh-tabor.de/sites/default/files/st...  \n",
       "25  https://www.ostfalia.de/export/system/modules/...  \n",
       "26  https://www.ostfalia.de/export/system/modules/...  \n",
       "27  https://www.ostfalia.de/export/system/modules/...  \n",
       "28  https://www.ostfalia.de/export/system/modules/...  \n",
       "29  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "30  https://www.phwt.de/wp-content/uploads/2020/09...  \n",
       "31  https://www.phwt.de/wp-content/uploads/2020/09...  \n",
       "32  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "33  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "34  https://www.jade-hs.de/fileadmin/layout2016/as...  \n",
       "35  https://www.jade-hs.de/fileadmin/layout2016/as...  \n",
       "36  https://www.jade-hs.de/fileadmin/layout2016/as...  \n",
       "37  https://www.steuerakademie.niedersachsen.de/as...  \n",
       "38  https://www.steuerakademie.niedersachsen.de/as...  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis_nd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "586d1ac8-2030-48e2-a662-531c4de9b9cf",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-dff62291b3fc7ab4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Um die Ausgabe auf ein wenige Elemente zu beschränken können die Funktion `head` und `tail` verwendet werden, die jeweils einen Eingabeparameter nehmen zu welcher Zeile Sie von oben bzw. unten den DataFrame anzeigen sollen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a0243d3a-1f2f-4fe9-b134-f13b37d8fc59",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3fd0f85fb2983ec4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "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>University name</th>\n",
       "      <th>Type of university</th>\n",
       "      <th>Sponsorship</th>\n",
       "      <th>Right of promotion</th>\n",
       "      <th>Founding year</th>\n",
       "      <th>Number of students</th>\n",
       "      <th>Address</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>plz</th>\n",
       "      <th>pic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Hochschule für Bildende Künste Braunschweig</td>\n",
       "      <td>Artistic university</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1963</td>\n",
       "      <td>976.0</td>\n",
       "      <td>Johannes-Selenka-Platz 1</td>\n",
       "      <td>52.257738</td>\n",
       "      <td>10.502315</td>\n",
       "      <td>38118 Braunschweig</td>\n",
       "      <td>https://www.hbk-bs.de/fileadmin/_processed_/5/...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Technische Universität Carolo-Wilhelmina zu Br...</td>\n",
       "      <td>University</td>\n",
       "      <td>public</td>\n",
       "      <td>yes</td>\n",
       "      <td>1745</td>\n",
       "      <td>17709.0</td>\n",
       "      <td>Universitätspl. 2</td>\n",
       "      <td>52.273550</td>\n",
       "      <td>10.530097</td>\n",
       "      <td>38106 Braunschweig</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hochschule 21</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>privat</td>\n",
       "      <td>no</td>\n",
       "      <td>2005</td>\n",
       "      <td>1084.0</td>\n",
       "      <td>Harburger Str. 6</td>\n",
       "      <td>53.477650</td>\n",
       "      <td>9.704650</td>\n",
       "      <td>21614 Buxtehude</td>\n",
       "      <td>https://upload.wikimedia.org/wikipedia/commons...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     University name  \\\n",
       "0        Hochschule für Bildende Künste Braunschweig   \n",
       "1  Technische Universität Carolo-Wilhelmina zu Br...   \n",
       "2                                      Hochschule 21   \n",
       "\n",
       "               Type of university Sponsorship Right of promotion  \\\n",
       "0             Artistic university      public                yes   \n",
       "1                      University      public                yes   \n",
       "2  University of Applied Sciences      privat                 no   \n",
       "\n",
       "   Founding year  Number of students                   Address        lat  \\\n",
       "0           1963               976.0  Johannes-Selenka-Platz 1  52.257738   \n",
       "1           1745             17709.0         Universitätspl. 2  52.273550   \n",
       "2           2005              1084.0          Harburger Str. 6  53.477650   \n",
       "\n",
       "         lon                 plz  \\\n",
       "0  10.502315  38118 Braunschweig   \n",
       "1  10.530097  38106 Braunschweig   \n",
       "2   9.704650     21614 Buxtehude   \n",
       "\n",
       "                                                 pic  \n",
       "0  https://www.hbk-bs.de/fileadmin/_processed_/5/...  \n",
       "1  https://upload.wikimedia.org/wikipedia/commons...  \n",
       "2  https://upload.wikimedia.org/wikipedia/commons...  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis_nd.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "57b9dcd0-b60f-434d-86c9-8786304e213f",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-6848848e5caa4c9e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "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>University name</th>\n",
       "      <th>Type of university</th>\n",
       "      <th>Sponsorship</th>\n",
       "      <th>Right of promotion</th>\n",
       "      <th>Founding year</th>\n",
       "      <th>Number of students</th>\n",
       "      <th>Address</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>plz</th>\n",
       "      <th>pic</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Jade Hochschule – Elsfleth</td>\n",
       "      <td>University of Applied Sciences</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2009</td>\n",
       "      <td>6789.0</td>\n",
       "      <td>Weserstraße 52</td>\n",
       "      <td>53.24244</td>\n",
       "      <td>8.46651</td>\n",
       "      <td>26931 Elsfleth</td>\n",
       "      <td>https://www.jade-hs.de/fileadmin/layout2016/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>Steuerakademie Niedersachsen Rinteln</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2006</td>\n",
       "      <td>500.0</td>\n",
       "      <td>Wilhelm-Busch-Weg 29</td>\n",
       "      <td>52.20696</td>\n",
       "      <td>9.09112</td>\n",
       "      <td>31737 Rinteln</td>\n",
       "      <td>https://www.steuerakademie.niedersachsen.de/as...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Steuerakademie Niedersachsen Bad Eilsen</td>\n",
       "      <td>University of Administration</td>\n",
       "      <td>public</td>\n",
       "      <td>no</td>\n",
       "      <td>2006</td>\n",
       "      <td>500.0</td>\n",
       "      <td>Bahnhofstraße 5</td>\n",
       "      <td>52.23981</td>\n",
       "      <td>9.10423</td>\n",
       "      <td>31707 Bad Eilsen</td>\n",
       "      <td>https://www.steuerakademie.niedersachsen.de/as...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            University name              Type of university  \\\n",
       "36               Jade Hochschule – Elsfleth  University of Applied Sciences   \n",
       "37     Steuerakademie Niedersachsen Rinteln    University of Administration   \n",
       "38  Steuerakademie Niedersachsen Bad Eilsen    University of Administration   \n",
       "\n",
       "   Sponsorship Right of promotion  Founding year  Number of students  \\\n",
       "36      public                 no           2009              6789.0   \n",
       "37      public                 no           2006               500.0   \n",
       "38      public                 no           2006               500.0   \n",
       "\n",
       "                 Address       lat      lon               plz  \\\n",
       "36        Weserstraße 52  53.24244  8.46651    26931 Elsfleth   \n",
       "37  Wilhelm-Busch-Weg 29  52.20696  9.09112     31737 Rinteln   \n",
       "38       Bahnhofstraße 5  52.23981  9.10423  31707 Bad Eilsen   \n",
       "\n",
       "                                                  pic  \n",
       "36  https://www.jade-hs.de/fileadmin/layout2016/as...  \n",
       "37  https://www.steuerakademie.niedersachsen.de/as...  \n",
       "38  https://www.steuerakademie.niedersachsen.de/as...  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis_nd.tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7573347e-593f-4dd8-a508-5037eb422628",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-cfdfb8a099225918",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Um zu prüfen welche Typen pandas den einzelnen Spalten gegeben hat könne Sie das Attribut `dtypes` verwenden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "36d674fe-56ff-4610-8086-adae93bdae62",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-900e418ddc2a0b14",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "University name        object\n",
       "Type of university     object\n",
       "Sponsorship            object\n",
       "Right of promotion     object\n",
       "Founding year           int64\n",
       "Number of students    float64\n",
       "Address                object\n",
       "lat                   float64\n",
       "lon                   float64\n",
       "plz                    object\n",
       "pic                    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis_nd.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "093b47e6-7d60-4507-b1d4-e17be1409bed",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-502b1bd3f4ce3db1",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Um eine gesamt Übersicht des Dataframes zu bekommen nutzen Sie die Funktion `info`.\n",
    "\n",
    "Aus dieser können Sie entnehmen in welcher Spalte _#_ wie viele Elemente _Non-Null Count_ vorhanden sind; den Namen der Spalte _Column_ und wie Pandas die Werte der Spalte _dtype_ interpretiert."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2ea51488-4dcb-4840-aae8-95bf54c226d0",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-c47dd110d6a97b52",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 39 entries, 0 to 38\n",
      "Data columns (total 11 columns):\n",
      " #   Column              Non-Null Count  Dtype  \n",
      "---  ------              --------------  -----  \n",
      " 0   University name     39 non-null     object \n",
      " 1   Type of university  39 non-null     object \n",
      " 2   Sponsorship         39 non-null     object \n",
      " 3   Right of promotion  39 non-null     object \n",
      " 4   Founding year       39 non-null     int64  \n",
      " 5   Number of students  39 non-null     float64\n",
      " 6   Address             39 non-null     object \n",
      " 7   lat                 39 non-null     float64\n",
      " 8   lon                 39 non-null     float64\n",
      " 9   plz                 39 non-null     object \n",
      " 10  pic                 39 non-null     object \n",
      "dtypes: float64(3), int64(1), object(7)\n",
      "memory usage: 3.5+ KB\n"
     ]
    }
   ],
   "source": [
    "unis_nd.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46bdc364-7bd2-4b50-bb74-b90d92312465",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d64d555865daff61",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Selecting Subsets\n",
    "\n",
    "![](https://pandas.pydata.org/docs/_images/03_subset_rows.svg)\n",
    "\n",
    "Wie Sie bereits aus dem ersten Kapitel Wissen können Sie einzelne Spalten mittels Schlüsselzugriff selektieren. Um mehr als eine Spalte zu Selektieren geben Sie dem Dataframe eine Liste der Schlüssel die sie auswählen möchten mit. Für alle weiterführenden Operationen zum Selektieren von Subsets lesen Sie gerne den [Getting started](https://pandas.pydata.org/docs/getting_started/intro_tutorials/03_subset_data.html) Guide zu Subset Data.\n",
    "\n",
    "Beispiel Selektion der Spalten _Sponsorship_ & _Founding year_: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "4078322c-7354-41ae-a9fa-3af389e37d41",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d98a6a7763f9ebc7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "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>Sponsorship</th>\n",
       "      <th>Founding year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>public</td>\n",
       "      <td>1963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>public</td>\n",
       "      <td>1745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>privat</td>\n",
       "      <td>2005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>public</td>\n",
       "      <td>1775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>public</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>privat</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>public</td>\n",
       "      <td>1737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>privat</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>public</td>\n",
       "      <td>1897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>privat</td>\n",
       "      <td>1920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>public</td>\n",
       "      <td>1963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>public</td>\n",
       "      <td>1778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>public</td>\n",
       "      <td>1831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>privat</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>public</td>\n",
       "      <td>1978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>public</td>\n",
       "      <td>1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>public</td>\n",
       "      <td>2007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>public</td>\n",
       "      <td>2007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>public</td>\n",
       "      <td>1973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>public</td>\n",
       "      <td>1973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>public</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>privat</td>\n",
       "      <td>1967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>privat</td>\n",
       "      <td>1998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>privat</td>\n",
       "      <td>1998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>public</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>privat</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>public</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>public</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>public</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>public</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>public</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Sponsorship  Founding year\n",
       "0       public           1963\n",
       "1       public           1745\n",
       "2       privat           2005\n",
       "3       public           1775\n",
       "4       public           2009\n",
       "5       privat           1995\n",
       "6       public           1737\n",
       "7       privat           1996\n",
       "8       public           1971\n",
       "9       public           1897\n",
       "10      privat           1920\n",
       "11      public           1963\n",
       "12      public           1778\n",
       "13      public           1831\n",
       "14      privat           2012\n",
       "15      public           1978\n",
       "16      public           1971\n",
       "17      public           1971\n",
       "18      public           1971\n",
       "19      public           1946\n",
       "20      public           2007\n",
       "21      public           2007\n",
       "22      public           1973\n",
       "23      public           1971\n",
       "24      public           1973\n",
       "25      public           1971\n",
       "26      public           1971\n",
       "27      public           1971\n",
       "28      public           1971\n",
       "29      privat           1967\n",
       "30      privat           1998\n",
       "31      privat           1998\n",
       "32      public           1995\n",
       "33      privat           2010\n",
       "34      public           2009\n",
       "35      public           2009\n",
       "36      public           2009\n",
       "37      public           2006\n",
       "38      public           2006"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unis_nd[[\"Sponsorship\", \"Founding year\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bef4ece8-00b0-486d-bba2-7f19e885cf6a",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-289af023470b6b19",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Aufgabe\n",
    "\n",
    "*2 Punkte*\n",
    "\n",
    "Selektieren Sie die Spalten _University name_, _Founding year_ & _Number of students_, speichern sie ihr Ergebnis in der Variablen `select`.\n",
    "\n",
    "Geben Sie danach die ersten 5 Werte von Oben der Selektion aus."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "040fa689-6062-44db-a6ea-b58113e41b65",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-2d560e3a83f1c48a",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "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>University name</th>\n",
       "      <th>Founding year</th>\n",
       "      <th>Number of students</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Hochschule für Bildende Künste Braunschweig</td>\n",
       "      <td>1963</td>\n",
       "      <td>976.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Technische Universität Carolo-Wilhelmina zu Br...</td>\n",
       "      <td>1745</td>\n",
       "      <td>17709.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hochschule 21</td>\n",
       "      <td>2005</td>\n",
       "      <td>1084.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Technische Universität Clausthal</td>\n",
       "      <td>1775</td>\n",
       "      <td>3446.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hochschule Emden/Leer</td>\n",
       "      <td>2009</td>\n",
       "      <td>4481.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     University name  Founding year  \\\n",
       "0        Hochschule für Bildende Künste Braunschweig           1963   \n",
       "1  Technische Universität Carolo-Wilhelmina zu Br...           1745   \n",
       "2                                      Hochschule 21           2005   \n",
       "3                   Technische Universität Clausthal           1775   \n",
       "4                              Hochschule Emden/Leer           2009   \n",
       "\n",
       "   Number of students  \n",
       "0               976.0  \n",
       "1             17709.0  \n",
       "2              1084.0  \n",
       "3              3446.0  \n",
       "4              4481.0  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "select = None\n",
    "\n",
    "### BEGIN SOLUTION\n",
    "select = unis_nd[[\"University name\", \"Founding year\", \"Number of students\"]]\n",
    "select.head(5)\n",
    "### END SOLUTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5bd633ac-afd9-4731-9c00-b494331d2dfb",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-108386a4387dbcc7",
     "locked": true,
     "points": 2,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Hier werden ihre Lösungen getestet\n",
    "assert isinstance(select, pd.DataFrame)\n",
    "assert list(select.keys()) == [\"University name\", \"Founding year\", \"Number of students\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9751208-b181-4764-b436-a57c5313d288",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-4fa720449b4af62e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Statistische Funktionen\n",
    "\n",
    "Wie in der Dokumentation beschrieben unterstützt Pandas verschiendene Statistische Funktion, welche direkt auf einen Data Frame angewendet werden können.\n",
    "\n",
    "Als Beispiel wird die Funktion `value_counts` auf die Spalte _Type of university_ gezeigt und im darauffolgenden Schritt als Kuchendiagramm geplottet. Das Ergebnis in der Variablen `count` ist eine `pd.Series`.\n",
    "\n",
    "Editor Side Note: Für den Plot verwende ich das Stylesheet von dhaitz, eines meiner absoluten Favouriten, dieses und mehrere finden Sie unter [github.com dhaitz](https://github.com/dhaitz/matplotlib-stylesheets). Mittels `plt.style.use` lassen sich externe Stylesheets verwenden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "14cc37af-13fa-49ce-af37-d327b16bda73",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-daa584941e3d78fe",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Type of university\n",
       "University of Applied Sciences    22\n",
       "University                        11\n",
       "University of Administration       4\n",
       "Artistic university                2\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "count = unis_nd[\"Type of university\"].value_counts()\n",
    "count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d8eff47d-e2e7-46c1-94ae-d344b3b62e0f",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-ea7ef2c3a9ada940",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 55944 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "format = lambda s: f'Quantity: %d\\n' % s +  f'In Percent: %1.1f%%' % s\n",
    "\n",
    "plt.style.use('https://github.com/dhaitz/matplotlib-stylesheets/raw/master/pitayasmoothie-dark.mplstyle') # Using my favourite Style\n",
    "plt.pie(count, labels=count.keys(), autopct=format, startangle=45, explode=[0, 0, 0, 0.2])\n",
    "plt.title(\"Types of Universities in lower Saxony (in %)\")\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1104848a-c149-4ef0-8835-aee9f4ad9f36",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-1c947f45fd0b2759",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Aufgabe\n",
    "\n",
    "*2 Punkte*\n",
    "\n",
    "Nutzen Sie die Funktion `value_counts` und erstellen Sie ein Balkendiagramm, mittels matplotlib, über die Anzahl an Staatlichen und Privaten Hochschulen Niedersachsen.\n",
    "\n",
    "Die dazugehörige Spalte im Datenset ist _Sponsorship_. Finden Sie eine geeignete Darstellung."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "1892e3fc-4d89-4966-bb36-b691a3d16ea4",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-fa553fbf09ed469b",
     "locked": false,
     "points": 2,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12260 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "### BEGIN SOLUTION\n",
    "c = unis_nd[\"Sponsorship\"].value_counts()\n",
    "plt.style.use('https://github.com/dhaitz/matplotlib-stylesheets/raw/master/pitayasmoothie-dark.mplstyle')\n",
    "plt.bar(c.keys(), c, color=[\"black\", \"white\"])\n",
    "plt.show()\n",
    "### END SOLUTION"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b420d70-9b7c-4e36-9b59-a44316af189a",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-cdcf1d5c71a5bfee",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Import Seaborn\n",
    "\n",
    "Auch hier waren die Entwickler uns einen Schritt vorraus und bevorzugen den Import von Seaborn mit dem Kürzel `sns`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b4e4202d-cf3f-4fa0-a66e-44ac08902cf2",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-0ab00ccadf1d74a7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt # Using it alongside sns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d10ef485-e7c4-4889-9e4f-61c765bf9384",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-25175b946c35845e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Setting a Theme\n",
    "\n",
    "Auch wenn MatPlotLib es möglichmacht hat seaborn eine simpleren Weg Themes anzuwenden. Schaue dir daher gerne die vorinstallierten Styles unter [Python Graph Gallery](https://python-graph-gallery.com/104-seaborn-themes/) an. Für die Folgenden Beispiele wird das Theme `darkgrid` verwendet.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1469effb-088e-4721-9a9c-f2fcc1423a1d",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-7587373683f9bc52",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "sns.set_style('darkgrid')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56a7f8ff-8899-4973-be0b-7a680302bfa4",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3151571f68fe985d",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Multidimensional Data Plotting\n",
    "\n",
    "Schauen wir uns im Folgenden an wie sich verschiedene Normalverteilte Größen in einem Plot unterbringen lassen.\n",
    "\n",
    "Dazu gehen wir davon aus das wir 60 Bienen, 3 verschiedener Arten gefangen haben und diese auf Länge und Anzahl an Parasiten untersuchen. Zunächst lässt sich feststellen das die Messwerkzeuge zum messen der Körperlängen nur auf 1 Dezimalstelle genau sind. \n",
    "Die Anzahl der Parasiten ist immer eine ganze Zahl, da wir keine Rückstände halber/toter Parasiten messen wollen. Diese werden zusammengebracht und mittels Seaborn geplottet.\n",
    "\n",
    "\n",
    "Hierzu werden 3 Bienenarten verwendet:\n",
    "\n",
    "|Biene|$\\mu$|$\\sigma$|Maximale Anzahl Parasiten|\n",
    "|-|-|-|-|\n",
    "|Fuchsrote Lockensandbiene|13 mm|1 mm|3|\n",
    "|Ackerhummel|12 mm|3 mm|4|\n",
    "|Platterbsen-Mörtelbiene|14 mm|1 mm|2|\n",
    "\n",
    "Im folgenden samplen wir von jeder Normalverteilten Körpergrößen der einzelnen Bienenarten 60 Samples:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "4a63a9b6-4a17-46d0-8708-b3ab35e329b1",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-54d90be534e41353",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "rng = np.random.default_rng(42)\n",
    "samples = 60\n",
    "\n",
    "# Sample lengths\n",
    "lockensandbiene_len = rng.normal(13, 1, samples)\n",
    "ackerhummel_len = rng.normal(12, 3, samples)\n",
    "mörtelbiene_len = rng.normal(14, 1, samples)\n",
    "\n",
    "# Sample Parasites\n",
    "lockensandbiene_par = rng.uniform(0, 3, samples)\n",
    "ackerhummel_par = rng.uniform(0, 4, samples)\n",
    "mörtelbiene_par = rng.uniform(0, 2, samples)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5f1d8d4-0910-4a65-91f3-26c18afdfcbe",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3154b2c952695029",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Aus den Samples lässt sich ein Dataset erstellen die wichtigen Attribute sind `species`, `length` & `parasites`. Nutzen wir dafür eine Dataclass erübrigt sich der Aufwand über listen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "e5cbfbe6-bf9a-4ab8-8a82-c0f7310907d3",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-a38996eee69926d9",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "from dataclasses import dataclass\n",
    "\n",
    "@dataclass\n",
    "class Bee:\n",
    "    species: str\n",
    "    length: np.float64\n",
    "    parasites: np.int64\n",
    "\n",
    "bees = list()\n",
    "\n",
    "# For every samples bee append to bees\n",
    "for bee_len, bee_par in zip(lockensandbiene_len, lockensandbiene_par):\n",
    "    b = Bee(species='Fuchsrote Lockensandbiene', length=np.round(bee_len, decimals=1), parasites=np.round(bee_par, decimals=0))\n",
    "    bees.append(b)\n",
    "for bee_len, bee_par in zip(ackerhummel_len, ackerhummel_par):\n",
    "    b = Bee(species='Ackerhummel', length=np.round(bee_len, decimals=1), parasites=np.round(bee_par, decimals=0))\n",
    "    bees.append(b)\n",
    "for bee_len, bee_par in zip(mörtelbiene_len, mörtelbiene_par):\n",
    "    b = Bee(species='Platterbsen-Mörtelbiene', length=np.round(bee_len, decimals=1), parasites=np.round(bee_par, decimals=0))\n",
    "    bees.append(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "453420f2-bfa5-448f-b353-7d2c150c86c8",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-1cffcdd63ad3fb6c",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Da ab diesem Schritt alle gesampleten Bienen geordnet und deklariert sind können wir mittels pandas einfach einen Dataframe erstellen und diesen speichern:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "e4954edf-ecf9-4097-aab3-de0abf5bc7e5",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-b17aafac68bb15b8",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "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>species</th>\n",
       "      <th>length</th>\n",
       "      <th>parasites</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Fuchsrote Lockensandbiene</td>\n",
       "      <td>13.3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Fuchsrote Lockensandbiene</td>\n",
       "      <td>12.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Fuchsrote Lockensandbiene</td>\n",
       "      <td>13.8</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Fuchsrote Lockensandbiene</td>\n",
       "      <td>13.9</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Fuchsrote Lockensandbiene</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>Platterbsen-Mörtelbiene</td>\n",
       "      <td>14.2</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>Platterbsen-Mörtelbiene</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>Platterbsen-Mörtelbiene</td>\n",
       "      <td>14.2</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>Platterbsen-Mörtelbiene</td>\n",
       "      <td>13.9</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>Platterbsen-Mörtelbiene</td>\n",
       "      <td>14.3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>180 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       species  length  parasites\n",
       "0    Fuchsrote Lockensandbiene    13.3        1.0\n",
       "1    Fuchsrote Lockensandbiene    12.0        2.0\n",
       "2    Fuchsrote Lockensandbiene    13.8        2.0\n",
       "3    Fuchsrote Lockensandbiene    13.9        1.0\n",
       "4    Fuchsrote Lockensandbiene    11.0        0.0\n",
       "..                         ...     ...        ...\n",
       "175    Platterbsen-Mörtelbiene    14.2        1.0\n",
       "176    Platterbsen-Mörtelbiene    15.6        1.0\n",
       "177    Platterbsen-Mörtelbiene    14.2        2.0\n",
       "178    Platterbsen-Mörtelbiene    13.9        0.0\n",
       "179    Platterbsen-Mörtelbiene    14.3        0.0\n",
       "\n",
       "[180 rows x 3 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bees_df = pd.DataFrame(bees)\n",
    "bees_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5e49fc8-e5f7-403d-9b56-3a560b92f0f4",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-b1092b46d45a70db",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Es hat Vorteile sich den Dataframe als CSV zu speichern dies versteht sich mittels:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "fec83133-43d8-40ae-b3d0-43dab722a671",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-735e7a0c1e9c3f9d",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "bees_df.to_csv('Bees.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5efba824-f0d2-4134-837d-1be4ce9d2e46",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-55ef638057716b7e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "In dem Notebook Ordner sollte eine Datei `Bees.csv` erstellt worden sein. Schaue sie dir gerne an.\n",
    "\n",
    "Seaborn macht es dementsprechend einfach. So verlangt `jointplot` ein Pandas DataFrame und für die `x` & `y` Koordinaten einfach den Namen der Spalten. um die Bienen voneinander zu Unterscheiden wird mit dem Parameter `hue` (Farbwert) nach Spezies gefärbt.\n",
    "\n",
    "Mit einer einzelenen Zeile ensteht dann folgender Plot.\n",
    "Dieser Zeigt die Anzahl an Parasiten für jede gesamplete Biene und an den Seiten die Normalverteilungen dieser:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "9778a0c6-0fb9-4b84-a8c5-e476dd7448a4",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3a931b591234c528",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 61848 characters]",
      "text/plain": [
       "<Figure size 600x600 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.jointplot(data=bees_df, x=\"length\", y=\"parasites\", hue=\"species\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46c69a61-fbd6-4c51-a749-a141ed0c8eca",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-38cb7d6f4529d85e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Mit dem `kind` Parameter lösst sich selbiger Plot auch als Histogramm anzeigen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "0b17470e-c9a0-4fd9-887e-eccbb3dead1f",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d0fb66b692b5eecd",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 29788 characters]",
      "text/plain": [
       "<Figure size 600x600 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.jointplot(data=bees_df, x=\"length\", y=\"parasites\", hue=\"species\", kind='hist')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22c86f08-23e9-4135-a3ef-4a6b1c86554c",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-d8aa28cae2c7b366",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "Aus dem Dataset lassen sich auch Multiplots erstellen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "29b3fe01-f7ca-4a2a-822f-cb147e12eece",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-37ffc1027bae59c4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 22736 characters]",
      "text/plain": [
       "<Figure size 900x300 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "grid = sns.FacetGrid(bees_df, col='species', hue='species')\n",
    "grid.map(sns.histplot, \"length\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4466fadd-e137-43ab-ba69-e4353cf54aad",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-11da2cf6fff4eafa",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Aufgabe\n",
    "\n",
    "*8 Punkte*\n",
    "\n",
    "Erstelle das Dataset `people_in_germany`.\n",
    "\n",
    "Folgendes Szenario:\n",
    "\n",
    "Du bist Part einer Massenhaft angelegten Studie um die bereits bekannten Zahlen des Statistischen Bundesamtes zu überprüfen.\n",
    "\n",
    "Dazu sind 4 Größen bekannt aus den Angaben des Statistischen Bundesamt für die [männliche Population](https://www.destatis.de/DE/Themen/Gesellschaft-Umwelt/Gesundheit/Gesundheitszustand-Relevantes-Verhalten/Tabellen/koerpermasse-maenner.html) & die [weibliche Population](https://www.destatis.de/DE/Themen/Gesellschaft-Umwelt/Gesundheit/Gesundheitszustand-Relevantes-Verhalten/Tabellen/koerpermasse-frauen.html):\n",
    "\n",
    "||Körpergröße (in cm)|Gewicht (in Kg)|\n",
    "|-|-|-|\n",
    "|Männlich|178.9|85.8|\n",
    "|Weiblich|165.8|69.2|\n",
    "\n",
    "Gehe dabei wie folgt vor:\n",
    "- Treffe annahmen über die Verteilung und finde geeignete Werte für $\\mu$ & $\\sigma$. **Erkläre** deine Annahmen mit einem kurzen Text.\n",
    "- Die Samplegröße beträgt 1000. Sample dementsprechend aus den gegebenen Werten.\n",
    "- Speichere die gesampleten Personen nach dem Schema: |gender|height|weight| in der File `people_in_germany.csv` als csv.\n",
    "  -> Nutze für das `gender` Attribut den Datentyp `bool` mit der Kodierung: `True = female` & `False = male`.\n",
    "- Stelle dein Ergebnis angemessen dar. Das theme `darkgrid` darf nicht verwendet werden.\n",
    "- **Beschreibe** & **Interpretiere** den Plot. Gehe dabei von der Hypothese aus das es **keine** Unterschiede zwischen den Geschlechtern beim samplen geben sollte.\n",
    "\n",
    "*Tipp: Dataclasses erleichtern die Aufgabe ungemein!*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "68702477-b09f-45ee-871d-da9a130f3319",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-0c8bc5e7c272cd4c",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 146288 characters]",
      "text/plain": [
       "<Figure size 600x600 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# BEGIN SOLUTION\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "from dataclasses import dataclass\n",
    "\n",
    "samples = 1000\n",
    "\n",
    "@dataclass\n",
    "class Individual:\n",
    "    gender: bool\n",
    "    height: np.float64\n",
    "    weight: np.float64\n",
    "    \n",
    "\n",
    "rng = np.random.default_rng()\n",
    "individuals = list()\n",
    "\n",
    "for i in range(samples):\n",
    "    if i % 2 == 0:\n",
    "        gender = False\n",
    "        height = rng.normal(178.9, 10)\n",
    "        weight = rng.normal(85.8, 26)\n",
    "                            \n",
    "    else:\n",
    "        gender = True\n",
    "        height = rng.normal(165.8, 11)\n",
    "        weight = rng.normal(69.2, 19)\n",
    "\n",
    "    height = np.round(height, decimals=1)\n",
    "    weight = np.round(weight, decimals=1)\n",
    "    \n",
    "    individual = Individual(gender=gender,height=height,weight=weight)\n",
    "    individuals.append(individual)\n",
    "\n",
    "individuals = pd.DataFrame(individuals)\n",
    "individuals.to_csv('people_in_germany.csv', index=False)\n",
    "\n",
    "sns.set_style('white')\n",
    "sns.jointplot(data=individuals, x=\"height\", y=\"weight\", hue=\"gender\")\n",
    "plt.show()\n",
    "# END SOLUTION"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fbcac55-ed91-4290-8026-639d215f783c",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-8b5f26594c6567ed",
     "locked": false,
     "points": 3,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "9d423664-b098-4fd4-9bad-5f7028424c87",
   "metadata": {
    "nbgrader": {
     "grade": true,
     "grade_id": "cell-3060604f60a0ca6f",
     "locked": true,
     "points": 8,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Hier werden ihre Lösungen getestet...\n",
    "test_individuals = pd.read_csv('people_in_germany.csv')\n",
    "assert len(test_individuals) > 999 # Test if enough samples where taken 1 Punkt\n",
    "assert list(test_individuals.columns) == ['gender', 'height', 'weight'] # Test if columns are correct 1 Punkt\n",
    "\n",
    "# Test gender means\n",
    "male_height = np.mean(test_individuals[test_individuals['gender'] == False]['height'])\n",
    "male_weight = np.mean(test_individuals[test_individuals['gender'] == False]['weight'])\n",
    "female_height = np.mean(test_individuals[test_individuals['gender'] == True]['height'])\n",
    "female_weight = np.mean(test_individuals[test_individuals['gender'] == True]['weight'])\n",
    "\n",
    "assert male_height > 176 and male_height < 182 # 1 Punkt\n",
    "assert male_weight > 83 and male_weight < 89 # 1 Punkt\n",
    "assert female_height > 163 and female_height < 169 # 1 Punkt\n",
    "assert female_weight > 66 and female_weight < 72 # 1 Punkt\n",
    "\n",
    "# test cummultative mean 1 Punkt\n",
    "assert test_individuals['height'].mean() > 170 and test_individuals['height'].mean() < 174 \n",
    "assert test_individuals['weight'].mean() > 75 and test_individuals['weight'].mean() < 80 "
   ]
  }
 ],
 "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.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
