{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"\n",
    "    border: 2px solid #4CAF50; \n",
    "    padding: 15px; \n",
    "    background-color: #f4f4f4; \n",
    "    border-radius: 10px; \n",
    "    align-items: center;\">\n",
    "\n",
    "<h1 style=\"margin: 0; color: #4CAF50;\">Einführung tabellarische Daten</h1>\n",
    "<h2 style=\"margin: 5px 0; color: #555;\">DSAI</h2>\n",
    "<h3 style=\"margin: 5px 0; color: #555;\">Jakob Eggl</h3>\n",
    "\n",
    "<div style=\"flex-shrink: 0;\">\n",
    "    <img src=\"https://www.htl-grieskirchen.at/wp/wp-content/uploads/2022/11/logo_bildschirm-1024x503.png\" alt=\"Logo\" style=\"width: 250px; height: auto;\"/>\n",
    "</div>\n",
    "<p1> © 2024/25 Jakob Eggl. Nutzung oder Verbreitung nur mit ausdrücklicher Genehmigung des Autors.</p1>\n",
    "</div>\n",
    "<div style=\"flex: 1;\">\n",
    "</div>   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Allgemeines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Viele Daten sind in tabellarischer Form\n",
    "* Gespeichert oft in csv, txt oder in zBsp. Datenbank\n",
    "* Einfach zu interpretieren\n",
    "* Gute Skalierbarkeit\n",
    "* Einfacher Austausch zwischen verschiedenen Systemen und Plattformen\n",
    "* Einfache Sortierung, Filterung, Aggregierung"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "source": [
    "## Aufbau und Eigenschaften"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "[encoded data, 190592 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Eigenschaften von Tabellen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Hat immer ein <em> \"Länge mal Breite </em> Format\"\n",
    "* Wird oft als Matrix modelliert (für numerische Daten zBsp mit $\\mathbb{R}^{m\\times n}$)\n",
    "* (Normalerweise) unabhängige Einträge (i.i.d.)\n",
    "* Verschiedene Datentypen: numerisch (float, int), text (string, char), leer (None, null, NaN, \"\")\n",
    "* Jede Spalte ist ein Feature -> Was ist ein Feature?\n",
    "* Jede Zeile ist ein Datenpunkt -> Was ist ein Datenpunkt?\n",
    "* Jede Spalte <em>kann </em> ein Label sein -> Was ist ein Label?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Feature"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Spalte des tabellarischen Datasets\n",
    "* Eine <em> Eigenschaft </em>\n",
    "* Label ist <em> kein </em> Feature\n",
    "* Kann/Muss oft normalisiert, aggregiert oder vorverarbeitet (preprocessing) werden, dadurch kann die Qualität des Features verbessert werden (kann aber auch schlechter werden)\n",
    "* Kann in Beziehung zu anderen Features stehen und durch Korrelationen oder Abhängigkeiten beeinflusst werden (ZBsp Feature \"Preis\" in einem Datensatz über Autos hängt meistens direkt mit der Leistung des Autos zusammen)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Datenpunkt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Zeile des tabellarischen Datasets\n",
    "* Steht für einen Eintrag\n",
    "* Je mehr Zeilen, desto mehr Daten\n",
    "* Quantität $\\neq$ Qualität:\n",
    "    * Können Duplikate beinhalten\n",
    "    * Daten modellieren vielleicht die \"echte Situation\" nicht gut\n",
    "    * Können leere Felder haben\n",
    "    * Können falsch sein (Umfragen etc.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Label"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Label ist quasi ein Namensschild bzw. eine Zugehörigkeit\n",
    "* Zbsp in diesem Titanic Dataset könnte man <em> survived </em> verwenden, um zu analysieren, welche Unterschiede zwischen Überlebenden und Nicht-Überlebenden bestehen/bestanden\n",
    "* Anderes Beispiel wäre aber auch Alter (Frauen und Kinder zuerst?), oder vielleicht eine geometrische Untersuchung mit den Cabin-Nummern (Vielleicht auf einer Seite der Kabine mehr Mortalitätsrate?)\n",
    "* Kann auch eine reelle Zahl (float) sein (Regression)\n",
    "* Analysen können auch ohne Label durchgeführt werden:\n",
    "    * Gruppierungen\n",
    "    * Dimensions-Reduzierung (zBsp.: PCA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Einführung in Pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Way to Go für Tabellarische Daten\n",
    "* Daten können aus verschiedenen Quellen eingelesen und ggf. auch wieder gespeichert werden (txt, csv, sql)\n",
    "* Eingelesene Daten werden in sogenannten <em>DataFrames</em> gespeichert\n",
    "* Es gibt auch <em>Series</em> als Datenstruktur für Listen- oder Array-ähnlichen Datenstrukturen\n",
    "* Pandas bietet eine flexible Indizierungsmöglichkeit\n",
    "* Viele statistische Größen (Mittelwert, Median, etc.) können einfach berechnet werden\n",
    "* Gute Integration mit weiteren Python-Bibliotheken (NumPy, Matplotlib, Scikit-Learn, etc.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Im folgenden wird nun Pandas anhand von einem Beispiel eingeführt. Dabei wird dieses Dataset in diesem Notebook überall verwendet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Importieren von Pandas\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Erstellung und Indizierung"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Wir erstellen ein Dataframe aus einer Liste ohne Index Spalte:\n",
    "\n",
    "df = pd.DataFrame({'Name'        : [\"Peter\", \"Karla\", \"Anne\", \"Nino\", \"Andrzej\"],\n",
    "                   'Geschlecht'  : ['M',pd.NA,'W','M','M'],\n",
    "                   'Alter'       : [45, 53, 16, 22, 61],\n",
    "                   'Größe'       : [1.77,1.72, 1.82, 1.71, 1.68],\n",
    "                   'Nationalität': [\"deutsch\", \"schweizerisch\", \"deutsch\", \"italienisch\", \"polnisch\"],\n",
    "                   'Gehalt'      : [3400, 4000, 0, pd.NA, 2300]\n",
    "                   }\n",
    "                  )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "0    Peter          M     45   1.77        deutsch   3400\n",
       "1    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "2     Anne          W     16   1.82        deutsch      0\n",
       "3     Nino          M     22   1.71    italienisch   <NA>\n",
       "4  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name               Anne\n",
       "Geschlecht            W\n",
       "Alter                16\n",
       "Größe              1.82\n",
       "Nationalität    deutsch\n",
       "Gehalt                0\n",
       "Name: 2, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Indizierung mit loc\n",
    "# Wir wählen die Zeile mit dem Index 2 aus\n",
    "df.loc[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name              Peter\n",
       "Geschlecht            M\n",
       "Alter                45\n",
       "Größe              1.77\n",
       "Nationalität    deutsch\n",
       "Gehalt             3400\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Indizierung mit iloc\n",
    "# Wir wählen die erste Zeile aus\n",
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Nun erstellen wir ein Dataframe aus einer Liste mit Index Spalte:\n",
    "\n",
    "df = pd.DataFrame({'Name'        : [\"Peter\", \"Karla\", \"Anne\", \"Nino\", \"Andrzej\"],\n",
    "                     'Geschlecht'  : ['M',pd.NA,'W','M','M'],\n",
    "                     'Alter'       : [45, 53, 16, 22, 61],\n",
    "                     'Größe'       : [1.77,1.72, 1.82, 1.71, 1.68],\n",
    "                     'Nationalität': [\"deutsch\", \"schweizerisch\", \"deutsch\", \"italienisch\", \"polnisch\"],\n",
    "                     'Gehalt'      : [3400, 4000, 0, pd.NA, 2300]\n",
    "                     },\n",
    "                    index = ['A', 'B', 'C', 'D', 'E']\n",
    "                    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "C     Anne          W     16   1.82        deutsch      0\n",
       "D     Nino          M     22   1.71    italienisch   <NA>\n",
       "E  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Index ist nun selber gewählt, vorher numerisch (0-4), nun (A-E)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name              Peter\n",
       "Geschlecht            M\n",
       "Alter                45\n",
       "Größe              1.77\n",
       "Nationalität    deutsch\n",
       "Gehalt             3400\n",
       "Name: A, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Indizierung mit Index\n",
    "\n",
    "df.loc['A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name              Peter\n",
       "Geschlecht            M\n",
       "Alter                45\n",
       "Größe              1.77\n",
       "Nationalität    deutsch\n",
       "Gehalt             3400\n",
       "Name: A, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc indizierung nach wie vor möglich um die 1. Zeile auszuwählen\n",
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Peter'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Wir können auch nur bestimmte Spalten auswählen\n",
    "df.loc['A', 'Name']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht\n",
       "A    Peter          M\n",
       "B    Karla       <NA>\n",
       "C     Anne          W\n",
       "D     Nino          M\n",
       "E  Andrzej          M"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Es ist auch die Indizierung von mehreren Spalten möglich\n",
    "df.loc[:, ['Name', 'Geschlecht']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Name Geschlecht\n",
       "A  Peter          M\n",
       "B  Karla       <NA>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Bzw. auch inklusive Zeilen\n",
    "df.loc[['A', 'B'], ['Name', 'Geschlecht']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Ebenso kann über eine Maske indiziert werden\n",
    "temp = df.loc[df['Alter'] > 20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "D     Nino          M     22   1.71    italienisch   <NA>\n",
       "E  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Mehrere Bedingungen können auch kombiniert werden\n",
    "temp = df.loc[(df['Alter'] > 20) & (df['Gehalt'] > 0)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "E  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Das Dataframe kann auch mittels SQL ähnlicher Syntax gefiltert werden\n",
    "temp = df.query('Alter > 20 & Größe > 1.71')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "A  Peter          M     45   1.77        deutsch   3400\n",
       "B  Karla       <NA>     53   1.72  schweizerisch   4000"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Die Ergebnisse sind Peter bzw. Peter\n"
     ]
    }
   ],
   "source": [
    "# Eine andere Art der Indizierung ist die Verwendung von at und iat\n",
    "# at und iat sind schneller als loc und iloc, da sie nur einen Wert zurückgeben\n",
    "\n",
    "# Beispiel:\n",
    "a = df.at['A', 'Name']\n",
    "b = df.iat[0, 0]\n",
    "\n",
    "print(f'Die Ergebnisse sind {a} bzw. {b}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
      "A  Peter Müller          M     45   1.77        deutsch   3400\n",
      "B         Karla       <NA>     53   1.72  schweizerisch   4000\n",
      "C          Anne          W     16   1.82        deutsch      0\n",
      "D          Nino          M     22   1.71    italienisch   <NA>\n",
      "E       Andrzej          M     61   1.68       polnisch   2300\n",
      "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
      "A    Peter          M     45   1.77        deutsch   3400\n",
      "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
      "C     Anne          W     16   1.82        deutsch      0\n",
      "D     Nino          M     22   1.71    italienisch   <NA>\n",
      "E  Andrzej          M     61   1.68       polnisch   2300\n"
     ]
    }
   ],
   "source": [
    "# at und iat können auch für das Setzen von Werten verwendet werden\n",
    "df.at['A', 'Name'] = 'Peter Müller'\n",
    "print(df)\n",
    "df.iat[0, 0] = 'Peter'\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iat und at liefert einen Fehler, wenn mehere Werte ausgegeben werden sollen\n",
    "# df.at[['A', 'B'], ['Name']] # Fehler: Richtig wäre die nächste Zeile\n",
    "# df.loc[['A', 'B'], ['Name']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Außerdem kann auch einfach wie bei einer Liste eine (oder mehrere) Spalte(n) ausgewählt werden\n",
    "names = df['Name']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A      Peter\n",
      "B      Karla\n",
      "C       Anne\n",
      "D       Nino\n",
      "E    Andrzej\n",
      "Name: Name, dtype: object\n"
     ]
    }
   ],
   "source": [
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.series.Series'>\n"
     ]
    }
   ],
   "source": [
    "print(type(names)) # Das Ergebnis ist nun eine Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Gleiches Ergebnis liefert die Adressierung via dem Punkt \".\" (Ähnlich wie bei Objekten)\n",
    "names = df.Name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A      Peter\n",
      "B      Karla\n",
      "C       Anne\n",
      "D       Nino\n",
      "E    Andrzej\n",
      "Name: Name, dtype: object\n"
     ]
    }
   ],
   "source": [
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.series.Series'>\n"
     ]
    }
   ],
   "source": [
    "print(type(names)) # Der Typ ist also auch gleich"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Spalten und Datentypen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Datentypen von Python und Pandas sind ähnlich, müssen aber dennoch unterschieden werden. Kann Pandas einen Datentyp nicht eindeutig zuordnen wird dieser automatisch als `object` angenommen. In numerischen Spalten ist dies meist ein Zeichen das Daten fehlen und diese zuerst bearbeitet (zBsp. beseitigt) werden müssen.\n",
    "\n",
    "\n",
    "| Pandas Type | Native Python Type  | Beschreibung          |\n",
    "|-------------|---------------------|-----------------------|\n",
    "| object      | string              | Zahlen und Strings    |\n",
    "| int64       | int                 | Ganzzahlen            |\n",
    "| float64     | float               | Gleitkomma           |\n",
    "| datetime64  | N/A                 | Datum und Zeit        |\n",
    "\n",
    "Verwende `info`() um Informationen über Datentypen und Spalten anzuzeigen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 5 entries, A to E\n",
      "Data columns (total 6 columns):\n",
      " #   Column        Non-Null Count  Dtype  \n",
      "---  ------        --------------  -----  \n",
      " 0   Name          5 non-null      object \n",
      " 1   Geschlecht    4 non-null      object \n",
      " 2   Alter         5 non-null      int64  \n",
      " 3   Größe         5 non-null      float64\n",
      " 4   Nationalität  5 non-null      object \n",
      " 5   Gehalt        4 non-null      object \n",
      "dtypes: float64(1), int64(1), object(4)\n",
      "memory usage: 452.0+ bytes\n"
     ]
    }
   ],
   "source": [
    "# Informationen über das Dataframe\n",
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.series.Series'>\n",
      "Index: 5 entries, A to E\n",
      "Series name: Name\n",
      "Non-Null Count  Dtype \n",
      "--------------  ----- \n",
      "5 non-null      object\n",
      "dtypes: object(1)\n",
      "memory usage: 252.0+ bytes\n"
     ]
    }
   ],
   "source": [
    "# Für beliebige Spalten kann folgendes verwendet werden\n",
    "df['Name'].info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In der Info wird auch angegeben, wie viele Werte None (=null) sind."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## NaN-Values und None/null"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Name  Geschlecht  Alter  Größe  Nationalität  Gehalt\n",
       "A  False       False  False  False         False   False\n",
       "B  False        True  False  False         False   False\n",
       "C  False       False  False  False         False   False\n",
       "D  False       False  False  False         False    True\n",
       "E  False       False  False  False         False   False"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Um die Felder anzuzeigen, welche fehlende Werte enthalten, verwenden wir den folgenden Befehl\n",
    "df.isna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Name  Geschlecht  Alter  Größe  Nationalität  Gehalt\n",
       "A  True        True   True   True          True    True\n",
       "B  True       False   True   True          True    True\n",
       "C  True        True   True   True          True    True\n",
       "D  True        True   True   True          True   False\n",
       "E  True        True   True   True          True    True"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Ähnlich können wir auch die Felder anzeigen, welche keine fehlenden Werte enthalten\n",
    "df.notna()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Warum ist es wichtig, solche Werte zu überprüfen bzw. sich mit sochen Werten zu befassen?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Um nan-Werte zu löschen, verwenden wir den folgenden Befehl\n",
    "cleaned_df = df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe Nationalität Gehalt\n",
       "A    Peter          M     45   1.77      deutsch   3400\n",
       "C     Anne          W     16   1.82      deutsch      0\n",
       "E  Andrzej          M     61   1.68     polnisch   2300"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Dies kann auch mit einzelnen Spalten gemacht werden\n",
    "cleaned_df_2 = df.dropna(subset=['Gehalt'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "C     Anne          W     16   1.82        deutsch      0\n",
       "E  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned_df_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NULL percent of column Geschlecht:  20.0 %\n",
      "NULL absolute of column Geschlecht:  1\n"
     ]
    }
   ],
   "source": [
    "column = 'Geschlecht'\n",
    "\n",
    "amount_null = df.filter([column]).isnull().sum() / len(df) * 100\n",
    "amount_null_count = df.filter([column]).isnull().sum()\n",
    "\n",
    "\n",
    "print(f'NULL percent of column {column}: ', amount_null.iloc[0], '%')\n",
    "print(f'NULL absolute of column {column}: ', amount_null_count.iloc[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sortieren und Filtern"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Verwende zum Sortieren des Dataframes die Methode `sort_values('Spalte')`. Verwende dabei `inplace`, damit die Änderungen direkt im aktuellen Dataframe durchgeführt werden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Wir sortieren zuerst nach dem Alter\n",
    "df.sort_values('Alter', inplace=True) # Wir verwenden inplace=True um das Dataframe zu überschreiben"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "C     Anne          W     16   1.82        deutsch      0\n",
       "D     Nino          M     22   1.71    italienisch   <NA>\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000\n",
       "E  Andrzej          M     61   1.68       polnisch   2300"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Wir können auch nach mehreren Spalten sortieren\n",
    "df.sort_values(['Geschlecht', 'Alter'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "D     Nino          M     22   1.71    italienisch   <NA>\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "E  Andrzej          M     61   1.68       polnisch   2300\n",
       "C     Anne          W     16   1.82        deutsch      0\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Wir können auch die Sortierung umkehren für jede der Spalten\n",
    "df.sort_values(['Geschlecht', 'Alter'], ascending=[False, False], inplace=True) # gleich wie ascending=False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "      <th>Größe</th>\n",
       "      <th>Nationalität</th>\n",
       "      <th>Gehalt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "      <td>1.82</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "      <td>1.68</td>\n",
       "      <td>polnisch</td>\n",
       "      <td>2300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "      <td>1.77</td>\n",
       "      <td>deutsch</td>\n",
       "      <td>3400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "      <td>1.71</td>\n",
       "      <td>italienisch</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "      <td>1.72</td>\n",
       "      <td>schweizerisch</td>\n",
       "      <td>4000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter  Größe   Nationalität Gehalt\n",
       "C     Anne          W     16   1.82        deutsch      0\n",
       "E  Andrzej          M     61   1.68       polnisch   2300\n",
       "A    Peter          M     45   1.77        deutsch   3400\n",
       "D     Nino          M     22   1.71    italienisch   <NA>\n",
       "B    Karla       <NA>     53   1.72  schweizerisch   4000"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Um zu filtern, können wir auch den folgenden Befehl verwenden, dieser ist sehr ähnlich zu der normalen Indizierung\n",
    "df_filtered = df.filter(['Name', 'Geschlecht', 'Alter'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Geschlecht</th>\n",
       "      <th>Alter</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>Anne</td>\n",
       "      <td>W</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>Andrzej</td>\n",
       "      <td>M</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>Peter</td>\n",
       "      <td>M</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>Nino</td>\n",
       "      <td>M</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>Karla</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name Geschlecht  Alter\n",
       "C     Anne          W     16\n",
       "E  Andrzej          M     61\n",
       "A    Peter          M     45\n",
       "D     Nino          M     22\n",
       "B    Karla       <NA>     53"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_filtered"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "C    False\n",
       "E    False\n",
       "A     True\n",
       "D    False\n",
       "B     True\n",
       "Name: Name, dtype: bool"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Um herauszufinden ob ein Wert in einer Spalte vorkommt, können wir folgenden Code verwenden\n",
    "\n",
    "df['Name'].isin(['Peter', 'Karla'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Datenimport und Datenexport in Pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Pandas stellt umfangreiche Methoden zum importieren, bearbeiten und speichern von Daten zur Verfügung.\n",
    "\n",
    "* Es werden zahlreiche Datenformate (.csv, .xlsx, .json, ...) unterstützt\n",
    "* Daten können Lokal oder OnLine gespeichert werden\n",
    "* Header können angepasst werden\n",
    "* Datentypen können angepasst werden\n",
    "* Spalten und Zeilen können verändert werden\n",
    "* Fehlende Werte können bearbeitet werden\n",
    "* ...\n",
    "\n",
    "<h3>Formate, welche unter anderem von Pandas unterstützt werden</h3>\n",
    "\n",
    "| Data Format |        Read       |            Save |\n",
    "| ------------ | :---------------: | --------------: |\n",
    "| csv          |  `pd.read_csv()`  |   `df.to_csv()` |\n",
    "| json         |  `pd.read_json()` |  `df.to_json()` |\n",
    "| excel        | `pd.read_excel()` | `df.to_excel()` |\n",
    "| hdf          |  `pd.read_hdf()`  |   `df.to_hdf()` |\n",
    "| sql          |  `pd.read_sql()`  |   `df.to_sql()` |\n",
    "| ...          |        ...        |             ... |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Laden aus einer CSV Datei"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wir verwenden das *Titanic* Dataset. Dieses ist nun gespeichert im Ordner `_data/titanic.csv`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "# wir verwenden dafür die Pakete os und pandas\n",
    "\n",
    "import os\n",
    "import pandas as pd # bereits vorher importiert"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset saved to path ..\\..\\_data\\titanic.csv\n"
     ]
    }
   ],
   "source": [
    "# Hilfsmethode\n",
    "\n",
    "path = os.path.join(\"..\", \"..\", \"_data\", \"titanic.csv\")\n",
    "\n",
    "if not os.path.exists(path):\n",
    "    os.makedirs(os.path.dirname(path), exist_ok=True)\n",
    "    df = pd.read_csv(\"https://raw.githubusercontent.com/rolandmueller/titanic/main/titanic3.csv\")\n",
    "    # df = sns.load_dataset(\"titanic\")\n",
    "    df.to_csv(path, index=False)\n",
    "    print(f\"Dataset saved to path {path}\")\n",
    "else:\n",
    "    print(\"Dataset is already existing\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = os.path.join(\"..\", \"..\", \"_data\", \"titanic.csv\")\n",
    "\n",
    "titanic = pd.read_csv(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                             name  \\\n",
       "0          1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1          1         1                   Allison, Master. Hudson Trevor   \n",
       "2          1         0                     Allison, Miss. Helen Loraine   \n",
       "3          1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4          1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...      ...       ...                                              ...   \n",
       "1304       3         0                             Zabour, Miss. Hileni   \n",
       "1305       3         0                            Zabour, Miss. Thamine   \n",
       "1306       3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307       3         0                              Zakarian, Mr. Ortin   \n",
       "1308       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S    2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S   11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...  ...   \n",
       "1304  female  14.5000      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1305  female      NaN      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1306    male  26.5000      0      0    2656    7.2250      NaN        C  NaN   \n",
       "1307    male  27.0000      0      0    2670    7.2250      NaN        C  NaN   \n",
       "1308    male  29.0000      0      0  315082    7.8750      NaN        S  NaN   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1304  328.0                              NaN  \n",
       "1305    NaN                              NaN  \n",
       "1306  304.0                              NaN  \n",
       "1307    NaN                              NaN  \n",
       "1308    NaN                              NaN  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wie wir sehen haben wir 1309 Zeilen (Datenpunkte) und 14 Spalten.\n",
    "\n",
    "Was ist hier das Label?\n",
    "\n",
    "Datasets können aber auch genau umgekehrt aufgebaut sein."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Transpornieren des Dataframes\n",
    "\n",
    "transposed_titanic = titanic.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>1299</th>\n",
       "      <th>1300</th>\n",
       "      <th>1301</th>\n",
       "      <th>1302</th>\n",
       "      <th>1303</th>\n",
       "      <th>1304</th>\n",
       "      <th>1305</th>\n",
       "      <th>1306</th>\n",
       "      <th>1307</th>\n",
       "      <th>1308</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>pclass</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>survived</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>Anderson, Mr. Harry</td>\n",
       "      <td>Andrews, Miss. Kornelia Theodosia</td>\n",
       "      <td>Andrews, Mr. Thomas Jr</td>\n",
       "      <td>Appleton, Mrs. Edward Dale (Charlotte Lamson)</td>\n",
       "      <td>Artagaveytia, Mr. Ramon</td>\n",
       "      <td>...</td>\n",
       "      <td>Yasbeck, Mr. Antoni</td>\n",
       "      <td>Yasbeck, Mrs. Antoni (Selini Alexander)</td>\n",
       "      <td>Youseff, Mr. Gerious</td>\n",
       "      <td>Yousif, Mr. Wazli</td>\n",
       "      <td>Yousseff, Mr. Gerious</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>male</td>\n",
       "      <td>male</td>\n",
       "      <td>female</td>\n",
       "      <td>female</td>\n",
       "      <td>male</td>\n",
       "      <td>male</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age</th>\n",
       "      <td>29.0</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>2.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>48.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>53.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>...</td>\n",
       "      <td>27.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>45.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26.5</td>\n",
       "      <td>27.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sibsp</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>parch</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ticket</th>\n",
       "      <td>24160</td>\n",
       "      <td>113781</td>\n",
       "      <td>113781</td>\n",
       "      <td>113781</td>\n",
       "      <td>113781</td>\n",
       "      <td>19952</td>\n",
       "      <td>13502</td>\n",
       "      <td>112050</td>\n",
       "      <td>11769</td>\n",
       "      <td>PC 17609</td>\n",
       "      <td>...</td>\n",
       "      <td>2659</td>\n",
       "      <td>2659</td>\n",
       "      <td>2628</td>\n",
       "      <td>2647</td>\n",
       "      <td>2627</td>\n",
       "      <td>2665</td>\n",
       "      <td>2665</td>\n",
       "      <td>2656</td>\n",
       "      <td>2670</td>\n",
       "      <td>315082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fare</th>\n",
       "      <td>211.3375</td>\n",
       "      <td>151.55</td>\n",
       "      <td>151.55</td>\n",
       "      <td>151.55</td>\n",
       "      <td>151.55</td>\n",
       "      <td>26.55</td>\n",
       "      <td>77.9583</td>\n",
       "      <td>0.0</td>\n",
       "      <td>51.4792</td>\n",
       "      <td>49.5042</td>\n",
       "      <td>...</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>7.225</td>\n",
       "      <td>7.225</td>\n",
       "      <td>14.4583</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>7.225</td>\n",
       "      <td>7.225</td>\n",
       "      <td>7.875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cabin</th>\n",
       "      <td>B5</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>E12</td>\n",
       "      <td>D7</td>\n",
       "      <td>A36</td>\n",
       "      <td>C101</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>embarked</th>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>S</td>\n",
       "      <td>C</td>\n",
       "      <td>...</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>boat</th>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>body</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>312.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>home.dest</th>\n",
       "      <td>St Louis, MO</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "      <td>New York, NY</td>\n",
       "      <td>Hudson, NY</td>\n",
       "      <td>Belfast, NI</td>\n",
       "      <td>Bayside, Queens, NY</td>\n",
       "      <td>Montevideo, Uruguay</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>14 rows × 1309 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    0                                1     \\\n",
       "pclass                                 1                                1   \n",
       "survived                               1                                1   \n",
       "name       Allen, Miss. Elisabeth Walton   Allison, Master. Hudson Trevor   \n",
       "sex                               female                             male   \n",
       "age                                 29.0                           0.9167   \n",
       "sibsp                                  0                                1   \n",
       "parch                                  0                                2   \n",
       "ticket                             24160                           113781   \n",
       "fare                            211.3375                           151.55   \n",
       "cabin                                 B5                          C22 C26   \n",
       "embarked                               S                                S   \n",
       "boat                                   2                               11   \n",
       "body                                 NaN                              NaN   \n",
       "home.dest                   St Louis, MO  Montreal, PQ / Chesterville, ON   \n",
       "\n",
       "                                      2     \\\n",
       "pclass                                   1   \n",
       "survived                                 0   \n",
       "name          Allison, Miss. Helen Loraine   \n",
       "sex                                 female   \n",
       "age                                    2.0   \n",
       "sibsp                                    1   \n",
       "parch                                    2   \n",
       "ticket                              113781   \n",
       "fare                                151.55   \n",
       "cabin                              C22 C26   \n",
       "embarked                                 S   \n",
       "boat                                   NaN   \n",
       "body                                   NaN   \n",
       "home.dest  Montreal, PQ / Chesterville, ON   \n",
       "\n",
       "                                           3     \\\n",
       "pclass                                        1   \n",
       "survived                                      0   \n",
       "name       Allison, Mr. Hudson Joshua Creighton   \n",
       "sex                                        male   \n",
       "age                                        30.0   \n",
       "sibsp                                         1   \n",
       "parch                                         2   \n",
       "ticket                                   113781   \n",
       "fare                                     151.55   \n",
       "cabin                                   C22 C26   \n",
       "embarked                                      S   \n",
       "boat                                        NaN   \n",
       "body                                      135.0   \n",
       "home.dest       Montreal, PQ / Chesterville, ON   \n",
       "\n",
       "                                                      4     \\\n",
       "pclass                                                   1   \n",
       "survived                                                 0   \n",
       "name       Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "sex                                                 female   \n",
       "age                                                   25.0   \n",
       "sibsp                                                    1   \n",
       "parch                                                    2   \n",
       "ticket                                              113781   \n",
       "fare                                                151.55   \n",
       "cabin                                              C22 C26   \n",
       "embarked                                                 S   \n",
       "boat                                                   NaN   \n",
       "body                                                   NaN   \n",
       "home.dest                  Montreal, PQ / Chesterville, ON   \n",
       "\n",
       "                          5                                  6     \\\n",
       "pclass                       1                                  1   \n",
       "survived                     1                                  1   \n",
       "name       Anderson, Mr. Harry  Andrews, Miss. Kornelia Theodosia   \n",
       "sex                       male                             female   \n",
       "age                       48.0                               63.0   \n",
       "sibsp                        0                                  1   \n",
       "parch                        0                                  0   \n",
       "ticket                   19952                              13502   \n",
       "fare                     26.55                            77.9583   \n",
       "cabin                      E12                                 D7   \n",
       "embarked                     S                                  S   \n",
       "boat                         3                                 10   \n",
       "body                       NaN                                NaN   \n",
       "home.dest         New York, NY                         Hudson, NY   \n",
       "\n",
       "                             7     \\\n",
       "pclass                          1   \n",
       "survived                        0   \n",
       "name       Andrews, Mr. Thomas Jr   \n",
       "sex                          male   \n",
       "age                          39.0   \n",
       "sibsp                           0   \n",
       "parch                           0   \n",
       "ticket                     112050   \n",
       "fare                          0.0   \n",
       "cabin                         A36   \n",
       "embarked                        S   \n",
       "boat                          NaN   \n",
       "body                          NaN   \n",
       "home.dest             Belfast, NI   \n",
       "\n",
       "                                                    8     \\\n",
       "pclass                                                 1   \n",
       "survived                                               1   \n",
       "name       Appleton, Mrs. Edward Dale (Charlotte Lamson)   \n",
       "sex                                               female   \n",
       "age                                                 53.0   \n",
       "sibsp                                                  2   \n",
       "parch                                                  0   \n",
       "ticket                                             11769   \n",
       "fare                                             51.4792   \n",
       "cabin                                               C101   \n",
       "embarked                                               S   \n",
       "boat                                                   D   \n",
       "body                                                 NaN   \n",
       "home.dest                            Bayside, Queens, NY   \n",
       "\n",
       "                              9     ...                 1299  \\\n",
       "pclass                           1  ...                    3   \n",
       "survived                         0  ...                    0   \n",
       "name       Artagaveytia, Mr. Ramon  ...  Yasbeck, Mr. Antoni   \n",
       "sex                           male  ...                 male   \n",
       "age                           71.0  ...                 27.0   \n",
       "sibsp                            0  ...                    1   \n",
       "parch                            0  ...                    0   \n",
       "ticket                    PC 17609  ...                 2659   \n",
       "fare                       49.5042  ...              14.4542   \n",
       "cabin                          NaN  ...                  NaN   \n",
       "embarked                         C  ...                    C   \n",
       "boat                           NaN  ...                    C   \n",
       "body                          22.0  ...                  NaN   \n",
       "home.dest      Montevideo, Uruguay  ...                  NaN   \n",
       "\n",
       "                                              1300                  1301  \\\n",
       "pclass                                           3                     3   \n",
       "survived                                         1                     0   \n",
       "name       Yasbeck, Mrs. Antoni (Selini Alexander)  Youseff, Mr. Gerious   \n",
       "sex                                         female                  male   \n",
       "age                                           15.0                  45.5   \n",
       "sibsp                                            1                     0   \n",
       "parch                                            0                     0   \n",
       "ticket                                        2659                  2628   \n",
       "fare                                       14.4542                 7.225   \n",
       "cabin                                          NaN                   NaN   \n",
       "embarked                                         C                     C   \n",
       "boat                                           NaN                   NaN   \n",
       "body                                           NaN                 312.0   \n",
       "home.dest                                      NaN                   NaN   \n",
       "\n",
       "                        1302                   1303                  1304  \\\n",
       "pclass                     3                      3                     3   \n",
       "survived                   0                      0                     0   \n",
       "name       Yousif, Mr. Wazli  Yousseff, Mr. Gerious  Zabour, Miss. Hileni   \n",
       "sex                     male                   male                female   \n",
       "age                      NaN                    NaN                  14.5   \n",
       "sibsp                      0                      0                     1   \n",
       "parch                      0                      0                     0   \n",
       "ticket                  2647                   2627                  2665   \n",
       "fare                   7.225                14.4583               14.4542   \n",
       "cabin                    NaN                    NaN                   NaN   \n",
       "embarked                   C                      C                     C   \n",
       "boat                     NaN                    NaN                   NaN   \n",
       "body                     NaN                    NaN                 328.0   \n",
       "home.dest                NaN                    NaN                   NaN   \n",
       "\n",
       "                            1305                       1306  \\\n",
       "pclass                         3                          3   \n",
       "survived                       0                          0   \n",
       "name       Zabour, Miss. Thamine  Zakarian, Mr. Mapriededer   \n",
       "sex                       female                       male   \n",
       "age                          NaN                       26.5   \n",
       "sibsp                          1                          0   \n",
       "parch                          0                          0   \n",
       "ticket                      2665                       2656   \n",
       "fare                     14.4542                      7.225   \n",
       "cabin                        NaN                        NaN   \n",
       "embarked                       C                          C   \n",
       "boat                         NaN                        NaN   \n",
       "body                         NaN                      304.0   \n",
       "home.dest                    NaN                        NaN   \n",
       "\n",
       "                          1307                1308  \n",
       "pclass                       3                   3  \n",
       "survived                     0                   0  \n",
       "name       Zakarian, Mr. Ortin  Zimmerman, Mr. Leo  \n",
       "sex                       male                male  \n",
       "age                       27.0                29.0  \n",
       "sibsp                        0                   0  \n",
       "parch                        0                   0  \n",
       "ticket                    2670              315082  \n",
       "fare                     7.225               7.875  \n",
       "cabin                      NaN                 NaN  \n",
       "embarked                     C                   S  \n",
       "boat                       NaN                 NaN  \n",
       "body                       NaN                 NaN  \n",
       "home.dest                  NaN                 NaN  \n",
       "\n",
       "[14 rows x 1309 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transposed_titanic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Es gibt einige andere Parameter, die beim Einlesen der Daten angepasst werden können. So kann explizit angegeben werden, welches Trennzeichen verwendet wird oder ob die erste Zeile als Header verwendet werden soll. Ebenso kann die Indexspalte explizit angegeben werden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Einlesen der Daten ohne Header\n",
    "titanic = pd.read_csv(path, header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "      <th>12</th>\n",
       "      <th>13</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>pclass</td>\n",
       "      <td>survived</td>\n",
       "      <td>name</td>\n",
       "      <td>sex</td>\n",
       "      <td>age</td>\n",
       "      <td>sibsp</td>\n",
       "      <td>parch</td>\n",
       "      <td>ticket</td>\n",
       "      <td>fare</td>\n",
       "      <td>cabin</td>\n",
       "      <td>embarked</td>\n",
       "      <td>boat</td>\n",
       "      <td>body</td>\n",
       "      <td>home.dest</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.55</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.55</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.55</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.225</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.225</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1309</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.875</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1310 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1                                     2       3       4   \\\n",
       "0     pclass  survived                                  name     sex     age   \n",
       "1          1         1         Allen, Miss. Elisabeth Walton  female    29.0   \n",
       "2          1         1        Allison, Master. Hudson Trevor    male  0.9167   \n",
       "3          1         0          Allison, Miss. Helen Loraine  female     2.0   \n",
       "4          1         0  Allison, Mr. Hudson Joshua Creighton    male    30.0   \n",
       "...      ...       ...                                   ...     ...     ...   \n",
       "1305       3         0                  Zabour, Miss. Hileni  female    14.5   \n",
       "1306       3         0                 Zabour, Miss. Thamine  female     NaN   \n",
       "1307       3         0             Zakarian, Mr. Mapriededer    male    26.5   \n",
       "1308       3         0                   Zakarian, Mr. Ortin    male    27.0   \n",
       "1309       3         0                    Zimmerman, Mr. Leo    male    29.0   \n",
       "\n",
       "         5      6       7         8        9         10    11     12  \\\n",
       "0     sibsp  parch  ticket      fare    cabin  embarked  boat   body   \n",
       "1         0      0   24160  211.3375       B5         S     2    NaN   \n",
       "2         1      2  113781    151.55  C22 C26         S    11    NaN   \n",
       "3         1      2  113781    151.55  C22 C26         S   NaN    NaN   \n",
       "4         1      2  113781    151.55  C22 C26         S   NaN  135.0   \n",
       "...     ...    ...     ...       ...      ...       ...   ...    ...   \n",
       "1305      1      0    2665   14.4542      NaN         C   NaN  328.0   \n",
       "1306      1      0    2665   14.4542      NaN         C   NaN    NaN   \n",
       "1307      0      0    2656     7.225      NaN         C   NaN  304.0   \n",
       "1308      0      0    2670     7.225      NaN         C   NaN    NaN   \n",
       "1309      0      0  315082     7.875      NaN         S   NaN    NaN   \n",
       "\n",
       "                                   13  \n",
       "0                           home.dest  \n",
       "1                        St Louis, MO  \n",
       "2     Montreal, PQ / Chesterville, ON  \n",
       "3     Montreal, PQ / Chesterville, ON  \n",
       "4     Montreal, PQ / Chesterville, ON  \n",
       "...                               ...  \n",
       "1305                              NaN  \n",
       "1306                              NaN  \n",
       "1307                              NaN  \n",
       "1308                              NaN  \n",
       "1309                              NaN  \n",
       "\n",
       "[1310 rows x 14 columns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Einlesen der Daten mit expliziter Angabe der Indexspalte\n",
    "titanic = pd.read_csv(path, index_col=\"age\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>29.0000</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.9167</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2.0000</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30.0000</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25.0000</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14.5000</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NaN</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26.5000</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27.0000</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29.0000</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         pclass  survived                                             name  \\\n",
       "age                                                                          \n",
       "29.0000       1         1                    Allen, Miss. Elisabeth Walton   \n",
       "0.9167        1         1                   Allison, Master. Hudson Trevor   \n",
       "2.0000        1         0                     Allison, Miss. Helen Loraine   \n",
       "30.0000       1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "25.0000       1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...         ...       ...                                              ...   \n",
       "14.5000       3         0                             Zabour, Miss. Hileni   \n",
       "NaN           3         0                            Zabour, Miss. Thamine   \n",
       "26.5000       3         0                        Zakarian, Mr. Mapriededer   \n",
       "27.0000       3         0                              Zakarian, Mr. Ortin   \n",
       "29.0000       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "            sex  sibsp  parch  ticket      fare    cabin embarked boat   body  \\\n",
       "age                                                                             \n",
       "29.0000  female      0      0   24160  211.3375       B5        S    2    NaN   \n",
       "0.9167     male      1      2  113781  151.5500  C22 C26        S   11    NaN   \n",
       "2.0000   female      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "30.0000    male      1      2  113781  151.5500  C22 C26        S  NaN  135.0   \n",
       "25.0000  female      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "...         ...    ...    ...     ...       ...      ...      ...  ...    ...   \n",
       "14.5000  female      1      0    2665   14.4542      NaN        C  NaN  328.0   \n",
       "NaN      female      1      0    2665   14.4542      NaN        C  NaN    NaN   \n",
       "26.5000    male      0      0    2656    7.2250      NaN        C  NaN  304.0   \n",
       "27.0000    male      0      0    2670    7.2250      NaN        C  NaN    NaN   \n",
       "29.0000    male      0      0  315082    7.8750      NaN        S  NaN    NaN   \n",
       "\n",
       "                               home.dest  \n",
       "age                                       \n",
       "29.0000                     St Louis, MO  \n",
       "0.9167   Montreal, PQ / Chesterville, ON  \n",
       "2.0000   Montreal, PQ / Chesterville, ON  \n",
       "30.0000  Montreal, PQ / Chesterville, ON  \n",
       "25.0000  Montreal, PQ / Chesterville, ON  \n",
       "...                                  ...  \n",
       "14.5000                              NaN  \n",
       "NaN                                  NaN  \n",
       "26.5000                              NaN  \n",
       "27.0000                              NaN  \n",
       "29.0000                              NaN  \n",
       "\n",
       "[1309 rows x 13 columns]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Bowerman, Miss. Elsie Edith</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>113505</td>\n",
       "      <td>55.0000</td>\n",
       "      <td>E33</td>\n",
       "      <td>S</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Leonards-on-Sea, England Ohio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cleaver, Miss. Alice</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Frolicher, Miss. Hedwig Margaritha</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>13568</td>\n",
       "      <td>49.5000</td>\n",
       "      <td>B39</td>\n",
       "      <td>C</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Zurich, Switzerland</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Gibson, Miss. Dorothy Winifred</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>112378</td>\n",
       "      <td>59.4000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>New York, NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Ostby, Miss. Helene Ragnhild</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>113509</td>\n",
       "      <td>61.9792</td>\n",
       "      <td>B36</td>\n",
       "      <td>C</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Providence, RI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Pears, Mrs. Thomas (Edith Wearne)</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113776</td>\n",
       "      <td>66.6000</td>\n",
       "      <td>C2</td>\n",
       "      <td>S</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Isleworth, England</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Ringhini, Mr. Sante</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17760</td>\n",
       "      <td>135.6333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>232.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Caldwell, Mrs. Albert Francis (Sylvia Mae Harb...</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>248738</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bangkok, Thailand / Roseville, IL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Cook, Mrs. (Selena Rogers)</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>W./C. 14266</td>\n",
       "      <td>10.5000</td>\n",
       "      <td>F33</td>\n",
       "      <td>S</td>\n",
       "      <td>14</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pennsylvania</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>Jefferys, Mr. Ernest Wilfred</td>\n",
       "      <td>male</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>C.A. 31029</td>\n",
       "      <td>31.5000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Guernsey / Elizabeth, NJ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>Karnes, Mrs. J Frank (Claire Bennett)</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>F.C.C. 13534</td>\n",
       "      <td>21.0000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>India / Pittsburgh, PA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Laroche, Mrs. Joseph (Juliette Marie Louise La...</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>SC/Paris 2123</td>\n",
       "      <td>41.5792</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>14</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Paris / Haiti</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>Oxenham, Mr. Percy Thomas</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>W./C. 14260</td>\n",
       "      <td>10.5000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pondersend, England / New Durham, NJ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Barton, Mr. David John</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>324669</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>England New York, NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Berglund, Mr. Karl Ivar Sven</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>PP 4348</td>\n",
       "      <td>9.3500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Tranvik, Finland New York</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Bradley, Miss. Bridget Delia</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>334914</td>\n",
       "      <td>7.7250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Q</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kingwilliamstown, Co Cork, Ireland Glens Falls...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bridgerule, Devon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Brobeck, Mr. Karl Rudolf</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>350045</td>\n",
       "      <td>7.7958</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Sweden Worcester, MA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Connolly, Miss. Kate</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>370373</td>\n",
       "      <td>7.7500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Q</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Ireland</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Dahlberg, Miss. Gerda Ulrika</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7552</td>\n",
       "      <td>10.5167</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Norrlot, Sweden Chicago, IL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Davies, Mr. Evan</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>SC/A4 23568</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Dennis, Mr. Samuel</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21172</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Dyker, Mrs. Adolf Fredrik (Anna Elisabeth Judi...</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>347072</td>\n",
       "      <td>13.9000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>16</td>\n",
       "      <td>NaN</td>\n",
       "      <td>West Haven, CT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Gilinski, Mr. Eliezer</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>14973</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>47.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Hellstrom, Miss. Hilda Maria</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7548</td>\n",
       "      <td>8.9625</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Hirvonen, Mrs. Alexander (Helga E Lindqvist)</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3101298</td>\n",
       "      <td>12.2875</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Johansson, Mr. Erik</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>350052</td>\n",
       "      <td>7.7958</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>156.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Karlsson, Mr. Nils August</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>350060</td>\n",
       "      <td>7.5208</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Kink, Miss. Maria</td>\n",
       "      <td>female</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>315152</td>\n",
       "      <td>8.6625</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Landergren, Miss. Aurora Adelia</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C 7077</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Larsson-Rondberg, Mr. Edvard A</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>347065</td>\n",
       "      <td>7.7750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Leeni, Mr. Fahim (\"Philip Zenni\")</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2620</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Maenpaa, Mr. Matti Alexanteri</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O 2. 3101275</td>\n",
       "      <td>7.1250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Naidenoff, Mr. Penko</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>349206</td>\n",
       "      <td>7.8958</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Nysten, Miss. Anna Sofia</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>347081</td>\n",
       "      <td>7.7500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Ohman, Miss. Velin</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>347085</td>\n",
       "      <td>7.7750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Perkin, Mr. John Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21174</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Riihivouri, Miss. Susanna Juhantytar \"Sanni\"</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3101295</td>\n",
       "      <td>39.6875</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Sirayanian, Mr. Orsen</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2669</td>\n",
       "      <td>7.2292</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Strandberg, Miss. Ida Sofia</td>\n",
       "      <td>female</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7553</td>\n",
       "      <td>9.8375</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Vartanian, Mr. David</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2658</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>13 15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Vovk, Mr. Janko</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>349252</td>\n",
       "      <td>7.8958</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22.0</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Waelens, Mr. Achille</td>\n",
       "      <td>male</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>345767</td>\n",
       "      <td>9.0000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Antwerp, Belgium / Stanton, OH</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                               name  \\\n",
       "age                                                                         \n",
       "22.0       1         1                        Bowerman, Miss. Elsie Edith   \n",
       "22.0       1         1                               Cleaver, Miss. Alice   \n",
       "22.0       1         1                 Frolicher, Miss. Hedwig Margaritha   \n",
       "22.0       1         1                     Gibson, Miss. Dorothy Winifred   \n",
       "22.0       1         1                       Ostby, Miss. Helene Ragnhild   \n",
       "22.0       1         1                  Pears, Mrs. Thomas (Edith Wearne)   \n",
       "22.0       1         0                                Ringhini, Mr. Sante   \n",
       "22.0       2         1  Caldwell, Mrs. Albert Francis (Sylvia Mae Harb...   \n",
       "22.0       2         1                         Cook, Mrs. (Selena Rogers)   \n",
       "22.0       2         0                       Jefferys, Mr. Ernest Wilfred   \n",
       "22.0       2         0              Karnes, Mrs. J Frank (Claire Bennett)   \n",
       "22.0       2         1  Laroche, Mrs. Joseph (Juliette Marie Louise La...   \n",
       "22.0       2         1                          Oxenham, Mr. Percy Thomas   \n",
       "22.0       3         0                             Barton, Mr. David John   \n",
       "22.0       3         0                       Berglund, Mr. Karl Ivar Sven   \n",
       "22.0       3         1                       Bradley, Miss. Bridget Delia   \n",
       "22.0       3         0                            Braund, Mr. Owen Harris   \n",
       "22.0       3         0                           Brobeck, Mr. Karl Rudolf   \n",
       "22.0       3         1                               Connolly, Miss. Kate   \n",
       "22.0       3         0                       Dahlberg, Miss. Gerda Ulrika   \n",
       "22.0       3         0                                   Davies, Mr. Evan   \n",
       "22.0       3         0                                 Dennis, Mr. Samuel   \n",
       "22.0       3         1  Dyker, Mrs. Adolf Fredrik (Anna Elisabeth Judi...   \n",
       "22.0       3         0                              Gilinski, Mr. Eliezer   \n",
       "22.0       3         1                       Hellstrom, Miss. Hilda Maria   \n",
       "22.0       3         1       Hirvonen, Mrs. Alexander (Helga E Lindqvist)   \n",
       "22.0       3         0                                Johansson, Mr. Erik   \n",
       "22.0       3         0                          Karlsson, Mr. Nils August   \n",
       "22.0       3         0                                  Kink, Miss. Maria   \n",
       "22.0       3         1                    Landergren, Miss. Aurora Adelia   \n",
       "22.0       3         0                     Larsson-Rondberg, Mr. Edvard A   \n",
       "22.0       3         1                  Leeni, Mr. Fahim (\"Philip Zenni\")   \n",
       "22.0       3         0                      Maenpaa, Mr. Matti Alexanteri   \n",
       "22.0       3         0                               Naidenoff, Mr. Penko   \n",
       "22.0       3         1                           Nysten, Miss. Anna Sofia   \n",
       "22.0       3         1                                 Ohman, Miss. Velin   \n",
       "22.0       3         0                             Perkin, Mr. John Henry   \n",
       "22.0       3         0       Riihivouri, Miss. Susanna Juhantytar \"Sanni\"   \n",
       "22.0       3         0                              Sirayanian, Mr. Orsen   \n",
       "22.0       3         0                        Strandberg, Miss. Ida Sofia   \n",
       "22.0       3         1                               Vartanian, Mr. David   \n",
       "22.0       3         0                                    Vovk, Mr. Janko   \n",
       "22.0       3         0                               Waelens, Mr. Achille   \n",
       "\n",
       "         sex  sibsp  parch             ticket      fare cabin embarked   boat  \\\n",
       "age                                                                             \n",
       "22.0  female      0      1             113505   55.0000   E33        S      6   \n",
       "22.0  female      0      0             113781  151.5500   NaN        S     11   \n",
       "22.0  female      0      2              13568   49.5000   B39        C      5   \n",
       "22.0  female      0      1             112378   59.4000   NaN        C      7   \n",
       "22.0  female      0      1             113509   61.9792   B36        C      5   \n",
       "22.0  female      1      0             113776   66.6000    C2        S      8   \n",
       "22.0    male      0      0           PC 17760  135.6333   NaN        C    NaN   \n",
       "22.0  female      1      1             248738   29.0000   NaN        S     13   \n",
       "22.0  female      0      0        W./C. 14266   10.5000   F33        S     14   \n",
       "22.0    male      2      0         C.A. 31029   31.5000   NaN        S    NaN   \n",
       "22.0  female      0      0       F.C.C. 13534   21.0000   NaN        S    NaN   \n",
       "22.0  female      1      2      SC/Paris 2123   41.5792   NaN        C     14   \n",
       "22.0    male      0      0        W./C. 14260   10.5000   NaN        S     13   \n",
       "22.0    male      0      0             324669    8.0500   NaN        S    NaN   \n",
       "22.0    male      0      0            PP 4348    9.3500   NaN        S    NaN   \n",
       "22.0  female      0      0             334914    7.7250   NaN        Q     13   \n",
       "22.0    male      1      0          A/5 21171    7.2500   NaN        S    NaN   \n",
       "22.0    male      0      0             350045    7.7958   NaN        S    NaN   \n",
       "22.0  female      0      0             370373    7.7500   NaN        Q     13   \n",
       "22.0  female      0      0               7552   10.5167   NaN        S    NaN   \n",
       "22.0    male      0      0        SC/A4 23568    8.0500   NaN        S    NaN   \n",
       "22.0    male      0      0          A/5 21172    7.2500   NaN        S    NaN   \n",
       "22.0  female      1      0             347072   13.9000   NaN        S     16   \n",
       "22.0    male      0      0              14973    8.0500   NaN        S    NaN   \n",
       "22.0  female      0      0               7548    8.9625   NaN        S      C   \n",
       "22.0  female      1      1            3101298   12.2875   NaN        S     15   \n",
       "22.0    male      0      0             350052    7.7958   NaN        S    NaN   \n",
       "22.0    male      0      0             350060    7.5208   NaN        S    NaN   \n",
       "22.0  female      2      0             315152    8.6625   NaN        S    NaN   \n",
       "22.0  female      0      0             C 7077    7.2500   NaN        S     13   \n",
       "22.0    male      0      0             347065    7.7750   NaN        S    NaN   \n",
       "22.0    male      0      0               2620    7.2250   NaN        C      6   \n",
       "22.0    male      0      0  STON/O 2. 3101275    7.1250   NaN        S    NaN   \n",
       "22.0    male      0      0             349206    7.8958   NaN        S    NaN   \n",
       "22.0  female      0      0             347081    7.7500   NaN        S     13   \n",
       "22.0  female      0      0             347085    7.7750   NaN        S      C   \n",
       "22.0    male      0      0          A/5 21174    7.2500   NaN        S    NaN   \n",
       "22.0  female      0      0            3101295   39.6875   NaN        S    NaN   \n",
       "22.0    male      0      0               2669    7.2292   NaN        C    NaN   \n",
       "22.0  female      0      0               7553    9.8375   NaN        S    NaN   \n",
       "22.0    male      0      0               2658    7.2250   NaN        C  13 15   \n",
       "22.0    male      0      0             349252    7.8958   NaN        S    NaN   \n",
       "22.0    male      0      0             345767    9.0000   NaN        S    NaN   \n",
       "\n",
       "       body                                          home.dest  \n",
       "age                                                             \n",
       "22.0    NaN                   St Leonards-on-Sea, England Ohio  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                Zurich, Switzerland  \n",
       "22.0    NaN                                       New York, NY  \n",
       "22.0    NaN                                     Providence, RI  \n",
       "22.0    NaN                                 Isleworth, England  \n",
       "22.0  232.0                                                NaN  \n",
       "22.0    NaN                  Bangkok, Thailand / Roseville, IL  \n",
       "22.0    NaN                                       Pennsylvania  \n",
       "22.0    NaN                           Guernsey / Elizabeth, NJ  \n",
       "22.0    NaN                             India / Pittsburgh, PA  \n",
       "22.0    NaN                                      Paris / Haiti  \n",
       "22.0    NaN               Pondersend, England / New Durham, NJ  \n",
       "22.0    NaN                               England New York, NY  \n",
       "22.0    NaN                          Tranvik, Finland New York  \n",
       "22.0    NaN  Kingwilliamstown, Co Cork, Ireland Glens Falls...  \n",
       "22.0    NaN                                  Bridgerule, Devon  \n",
       "22.0    NaN                               Sweden Worcester, MA  \n",
       "22.0    NaN                                            Ireland  \n",
       "22.0    NaN                        Norrlot, Sweden Chicago, IL  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                     West Haven, CT  \n",
       "22.0   47.0                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0  156.0                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                                                NaN  \n",
       "22.0    NaN                     Antwerp, Belgium / Stanton, OH  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Achtung: Index ist nicht mehr eindeutig\n",
    "\n",
    "# Hier filtern wir nach allen Personen dem Alter von 22 Jahren\n",
    "titanic.loc[22]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Nun verwenden wir das Geschlecht als Index\n",
    "titanic = pd.read_csv(path, index_col='sex')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        pclass  survived                                             name  \\\n",
       "sex                                                                         \n",
       "female       1         1                    Allen, Miss. Elisabeth Walton   \n",
       "male         1         1                   Allison, Master. Hudson Trevor   \n",
       "female       1         0                     Allison, Miss. Helen Loraine   \n",
       "male         1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "female       1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...        ...       ...                                              ...   \n",
       "female       3         0                             Zabour, Miss. Hileni   \n",
       "female       3         0                            Zabour, Miss. Thamine   \n",
       "male         3         0                        Zakarian, Mr. Mapriededer   \n",
       "male         3         0                              Zakarian, Mr. Ortin   \n",
       "male         3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "            age  sibsp  parch  ticket      fare    cabin embarked boat   body  \\\n",
       "sex                                                                             \n",
       "female  29.0000      0      0   24160  211.3375       B5        S    2    NaN   \n",
       "male     0.9167      1      2  113781  151.5500  C22 C26        S   11    NaN   \n",
       "female   2.0000      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "male    30.0000      1      2  113781  151.5500  C22 C26        S  NaN  135.0   \n",
       "female  25.0000      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "...         ...    ...    ...     ...       ...      ...      ...  ...    ...   \n",
       "female  14.5000      1      0    2665   14.4542      NaN        C  NaN  328.0   \n",
       "female      NaN      1      0    2665   14.4542      NaN        C  NaN    NaN   \n",
       "male    26.5000      0      0    2656    7.2250      NaN        C  NaN  304.0   \n",
       "male    27.0000      0      0    2670    7.2250      NaN        C  NaN    NaN   \n",
       "male    29.0000      0      0  315082    7.8750      NaN        S  NaN    NaN   \n",
       "\n",
       "                              home.dest  \n",
       "sex                                      \n",
       "female                     St Louis, MO  \n",
       "male    Montreal, PQ / Chesterville, ON  \n",
       "female  Montreal, PQ / Chesterville, ON  \n",
       "male    Montreal, PQ / Chesterville, ON  \n",
       "female  Montreal, PQ / Chesterville, ON  \n",
       "...                                 ...  \n",
       "female                              NaN  \n",
       "female                              NaN  \n",
       "male                                NaN  \n",
       "male                                NaN  \n",
       "male                                NaN  \n",
       "\n",
       "[1309 rows x 13 columns]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>25.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Andrews, Miss. Kornelia Theodosia</td>\n",
       "      <td>63.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>13502</td>\n",
       "      <td>77.9583</td>\n",
       "      <td>D7</td>\n",
       "      <td>S</td>\n",
       "      <td>10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Hudson, NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Appleton, Mrs. Edward Dale (Charlotte Lamson)</td>\n",
       "      <td>53.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>11769</td>\n",
       "      <td>51.4792</td>\n",
       "      <td>C101</td>\n",
       "      <td>S</td>\n",
       "      <td>D</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Bayside, Queens, NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Whabee, Mrs. George Joseph (Shawneene Abi-Saab)</td>\n",
       "      <td>38.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2688</td>\n",
       "      <td>7.2292</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Wilkes, Mrs. James (Ellen Needs)</td>\n",
       "      <td>47.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>363272</td>\n",
       "      <td>7.0000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Yasbeck, Mrs. Antoni (Selini Alexander)</td>\n",
       "      <td>15.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2659</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>14.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>466 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        pclass  survived                                             name  \\\n",
       "sex                                                                         \n",
       "female       1         1                    Allen, Miss. Elisabeth Walton   \n",
       "female       1         0                     Allison, Miss. Helen Loraine   \n",
       "female       1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "female       1         1                Andrews, Miss. Kornelia Theodosia   \n",
       "female       1         1    Appleton, Mrs. Edward Dale (Charlotte Lamson)   \n",
       "...        ...       ...                                              ...   \n",
       "female       3         1  Whabee, Mrs. George Joseph (Shawneene Abi-Saab)   \n",
       "female       3         1                 Wilkes, Mrs. James (Ellen Needs)   \n",
       "female       3         1          Yasbeck, Mrs. Antoni (Selini Alexander)   \n",
       "female       3         0                             Zabour, Miss. Hileni   \n",
       "female       3         0                            Zabour, Miss. Thamine   \n",
       "\n",
       "         age  sibsp  parch  ticket      fare    cabin embarked boat   body  \\\n",
       "sex                                                                          \n",
       "female  29.0      0      0   24160  211.3375       B5        S    2    NaN   \n",
       "female   2.0      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "female  25.0      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "female  63.0      1      0   13502   77.9583       D7        S   10    NaN   \n",
       "female  53.0      2      0   11769   51.4792     C101        S    D    NaN   \n",
       "...      ...    ...    ...     ...       ...      ...      ...  ...    ...   \n",
       "female  38.0      0      0    2688    7.2292      NaN        C    C    NaN   \n",
       "female  47.0      1      0  363272    7.0000      NaN        S  NaN    NaN   \n",
       "female  15.0      1      0    2659   14.4542      NaN        C  NaN    NaN   \n",
       "female  14.5      1      0    2665   14.4542      NaN        C  NaN  328.0   \n",
       "female   NaN      1      0    2665   14.4542      NaN        C  NaN    NaN   \n",
       "\n",
       "                              home.dest  \n",
       "sex                                      \n",
       "female                     St Louis, MO  \n",
       "female  Montreal, PQ / Chesterville, ON  \n",
       "female  Montreal, PQ / Chesterville, ON  \n",
       "female                       Hudson, NY  \n",
       "female              Bayside, Queens, NY  \n",
       "...                                 ...  \n",
       "female                              NaN  \n",
       "female                              NaN  \n",
       "female                              NaN  \n",
       "female                              NaN  \n",
       "female                              NaN  \n",
       "\n",
       "[466 rows x 13 columns]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic.loc['female']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Einlesen der Daten mit expliziter Angabe des Trennzeichens\n",
    "titanic = pd.read_csv(path, sep=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                             name  \\\n",
       "0          1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1          1         1                   Allison, Master. Hudson Trevor   \n",
       "2          1         0                     Allison, Miss. Helen Loraine   \n",
       "3          1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4          1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...      ...       ...                                              ...   \n",
       "1304       3         0                             Zabour, Miss. Hileni   \n",
       "1305       3         0                            Zabour, Miss. Thamine   \n",
       "1306       3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307       3         0                              Zakarian, Mr. Ortin   \n",
       "1308       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S    2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S   11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...  ...   \n",
       "1304  female  14.5000      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1305  female      NaN      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1306    male  26.5000      0      0    2656    7.2250      NaN        C  NaN   \n",
       "1307    male  27.0000      0      0    2670    7.2250      NaN        C  NaN   \n",
       "1308    male  29.0000      0      0  315082    7.8750      NaN        S  NaN   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1304  328.0                              NaN  \n",
       "1305    NaN                              NaN  \n",
       "1306  304.0                              NaN  \n",
       "1307    NaN                              NaN  \n",
       "1308    NaN                              NaN  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In manchen Fällen kann das Trennzeichen (zBsp \",\") Probleme machen (zBsp Tausender-Trennzeichen oder als Gleitkomma für floats)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "# In so einem Fall kann dann die eigene Option decimal verwendet werden\n",
    "titanic = pd.read_csv(path, sep=\",\", decimal=\".\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                             name  \\\n",
       "0          1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1          1         1                   Allison, Master. Hudson Trevor   \n",
       "2          1         0                     Allison, Miss. Helen Loraine   \n",
       "3          1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4          1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...      ...       ...                                              ...   \n",
       "1304       3         0                             Zabour, Miss. Hileni   \n",
       "1305       3         0                            Zabour, Miss. Thamine   \n",
       "1306       3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307       3         0                              Zakarian, Mr. Ortin   \n",
       "1308       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S    2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S   11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...  ...   \n",
       "1304  female  14.5000      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1305  female      NaN      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1306    male  26.5000      0      0    2656    7.2250      NaN        C  NaN   \n",
       "1307    male  27.0000      0      0    2670    7.2250      NaN        C  NaN   \n",
       "1308    male  29.0000      0      0  315082    7.8750      NaN        S  NaN   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1304  328.0                              NaN  \n",
       "1305    NaN                              NaN  \n",
       "1306  304.0                              NaN  \n",
       "1307    NaN                              NaN  \n",
       "1308    NaN                              NaN  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Falls es keinen Header gibt, kann dieser selber erstellt werden mit dem `names` argument"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>own_class</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>328.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      own_class  survived                                             name  \\\n",
       "0             1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1             1         1                   Allison, Master. Hudson Trevor   \n",
       "2             1         0                     Allison, Miss. Helen Loraine   \n",
       "3             1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4             1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...         ...       ...                                              ...   \n",
       "1304          3         0                             Zabour, Miss. Hileni   \n",
       "1305          3         0                            Zabour, Miss. Thamine   \n",
       "1306          3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307          3         0                              Zakarian, Mr. Ortin   \n",
       "1308          3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S    2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S   11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  NaN   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...  ...   \n",
       "1304  female  14.5000      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1305  female      NaN      1      0    2665   14.4542      NaN        C  NaN   \n",
       "1306    male  26.5000      0      0    2656    7.2250      NaN        C  NaN   \n",
       "1307    male  27.0000      0      0    2670    7.2250      NaN        C  NaN   \n",
       "1308    male  29.0000      0      0  315082    7.8750      NaN        S  NaN   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1304  328.0                              NaN  \n",
       "1305    NaN                              NaN  \n",
       "1306  304.0                              NaN  \n",
       "1307    NaN                              NaN  \n",
       "1308    NaN                              NaN  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "own_header_titanic = pd.read_csv(path, header=0, names=['own_class', 'survived', 'name', 'sex', 'age', 'sibsp', 'parch', 'ticket', 'fare', 'cabin', 'embarked', 'boat', 'body', 'home.dest'])\n",
    "\n",
    "own_header_titanic # würde auch funktionieren wenn kein header gegeben wäre"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In unserem Fall wollen wir die Namen beibehalten, sprich wir verwenden die gleichen Spaltennamen wie im originalen Datenset. Um die Spaltennamen des ursprünglichen Datensets zu erhalten verwenden wir den `columns()` Befehl."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Alle Spaltennamen erhalten\n",
    "columns = titanic.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pclass', 'survived', 'name', 'sex', 'age', 'sibsp', 'parch', 'ticket',\n",
       "       'fare', 'cabin', 'embarked', 'boat', 'body', 'home.dest'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1309 entries, 0 to 1308\n",
      "Data columns (total 14 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   pclass     1309 non-null   int64  \n",
      " 1   survived   1309 non-null   int64  \n",
      " 2   name       1309 non-null   object \n",
      " 3   sex        1309 non-null   object \n",
      " 4   age        1046 non-null   float64\n",
      " 5   sibsp      1309 non-null   int64  \n",
      " 6   parch      1309 non-null   int64  \n",
      " 7   ticket     1309 non-null   object \n",
      " 8   fare       1308 non-null   float64\n",
      " 9   cabin      295 non-null    object \n",
      " 10  embarked   1307 non-null   object \n",
      " 11  boat       486 non-null    object \n",
      " 12  body       121 non-null    float64\n",
      " 13  home.dest  745 non-null    object \n",
      "dtypes: float64(3), int64(4), object(7)\n",
      "memory usage: 143.3+ KB\n"
     ]
    }
   ],
   "source": [
    "# Ausgeben lassen der Informationen über die Spalten inklusive Null-Count:\n",
    "titanic.info()\n",
    "\n",
    "# Weitere Infos findet man oft auf der Webseite des Datesets, in diesem Fall: https://www.kaggle.com/c/titanic/data (Achtung, nicht genau das gleiche Dataset, in diesem Fall bereits bereinigt und aufgteilt in train und test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wir sehen, manche Spalten sind als Typ `object`, obwohl sie zbsp als string durchgehen könnten. Richtige Datentypen sind wichtig, da so dann mehr Methoden zur Verfügung stehen."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Für manche Spalten ist es aber dann Vorteilhaft, die <em>null</em> bzw. <em>None</em> Werte davor zu befüllen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Betrachten wir die Spalte home.dest:\n",
    "# Die Daten sind eigentlich Werte des Typs string, aber es wird als object interpretiert -> Dies ändern wir nun\n",
    "\n",
    "# Füllen der Daten mit dem Wert '' (leerer String)\n",
    "titanic['home.dest'] = titanic['home.dest'].fillna(value='')\n",
    "\n",
    "\n",
    "titanic['home.dest'] = titanic[\"home.dest\"].astype(\"string\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1309 entries, 0 to 1308\n",
      "Data columns (total 14 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   pclass     1309 non-null   int64  \n",
      " 1   survived   1309 non-null   int64  \n",
      " 2   name       1309 non-null   object \n",
      " 3   sex        1309 non-null   object \n",
      " 4   age        1046 non-null   float64\n",
      " 5   sibsp      1309 non-null   int64  \n",
      " 6   parch      1309 non-null   int64  \n",
      " 7   ticket     1309 non-null   object \n",
      " 8   fare       1308 non-null   float64\n",
      " 9   cabin      295 non-null    object \n",
      " 10  embarked   1307 non-null   object \n",
      " 11  boat       486 non-null    object \n",
      " 12  body       121 non-null    float64\n",
      " 13  home.dest  1309 non-null   string \n",
      "dtypes: float64(3), int64(4), object(6), string(1)\n",
      "memory usage: 143.3+ KB\n"
     ]
    }
   ],
   "source": [
    "titanic.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                          St Louis, MO\n",
       "1       Montreal, PQ / Chesterville, ON\n",
       "2       Montreal, PQ / Chesterville, ON\n",
       "3       Montreal, PQ / Chesterville, ON\n",
       "4       Montreal, PQ / Chesterville, ON\n",
       "                     ...               \n",
       "1304                                   \n",
       "1305                                   \n",
       "1306                                   \n",
       "1307                                   \n",
       "1308                                   \n",
       "Name: home.dest, Length: 1309, dtype: string"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic['home.dest']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wenn im Vorhinein die Datentypen schon feststehen, können auch diese beim Einlesen verwendet werden. Dafür muss ein Dictionary für das Argument `dtype` übergeben werden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Einlesen der Daten mit home.dest als String\n",
    "titanic = pd.read_csv(path, dtype={\"home.dest\": 'string'}, header=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1309 entries, 0 to 1308\n",
      "Data columns (total 14 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   pclass     1309 non-null   int64  \n",
      " 1   survived   1309 non-null   int64  \n",
      " 2   name       1309 non-null   object \n",
      " 3   sex        1309 non-null   object \n",
      " 4   age        1046 non-null   float64\n",
      " 5   sibsp      1309 non-null   int64  \n",
      " 6   parch      1309 non-null   int64  \n",
      " 7   ticket     1309 non-null   object \n",
      " 8   fare       1308 non-null   float64\n",
      " 9   cabin      295 non-null    object \n",
      " 10  embarked   1307 non-null   object \n",
      " 11  boat       486 non-null    object \n",
      " 12  body       121 non-null    float64\n",
      " 13  home.dest  745 non-null    string \n",
      "dtypes: float64(3), int64(4), object(6), string(1)\n",
      "memory usage: 143.3+ KB\n"
     ]
    }
   ],
   "source": [
    "titanic.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                          St Louis, MO\n",
       "1       Montreal, PQ / Chesterville, ON\n",
       "2       Montreal, PQ / Chesterville, ON\n",
       "3       Montreal, PQ / Chesterville, ON\n",
       "4       Montreal, PQ / Chesterville, ON\n",
       "                     ...               \n",
       "1304                               <NA>\n",
       "1305                               <NA>\n",
       "1306                               <NA>\n",
       "1307                               <NA>\n",
       "1308                               <NA>\n",
       "Name: home.dest, Length: 1309, dtype: string"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic['home.dest']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Es können auch sogenannte na-filter verwendet (und adaptiert) bzw. deaktiviert werden, welche Pandas ggf. unterbinden, leere String und dergleichen mit einen <b>NaN</b>-Symbol zu ersetzen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Einlesen mit na_filter = False\n",
    "titanic = pd.read_csv(path, na_filter=False, header=0, dtype={\"home.dest\": 'string'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                          St Louis, MO\n",
       "1       Montreal, PQ / Chesterville, ON\n",
       "2       Montreal, PQ / Chesterville, ON\n",
       "3       Montreal, PQ / Chesterville, ON\n",
       "4       Montreal, PQ / Chesterville, ON\n",
       "                     ...               \n",
       "1304                                   \n",
       "1305                                   \n",
       "1306                                   \n",
       "1307                                   \n",
       "1308                                   \n",
       "Name: home.dest, Length: 1309, dtype: string"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic['home.dest']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic = pd.read_csv(path, header=0, sep=',', index_col=False, decimal='.')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Speichern eines Dataframes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wie am Anfang erwähnt können die Dataframes auch in einer Datei gespeichert werden."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "# speichern des dataframes als json\n",
    "\n",
    "path = os.path.join(\"..\", \"..\", \"_data\", \"titanic.json\")\n",
    "\n",
    "titanic.to_json(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Laden der json Datei:\n",
    "titanic = pd.read_json(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>328.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>304.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                             name  \\\n",
       "0          1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1          1         1                   Allison, Master. Hudson Trevor   \n",
       "2          1         0                     Allison, Miss. Helen Loraine   \n",
       "3          1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4          1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...      ...       ...                                              ...   \n",
       "1304       3         0                             Zabour, Miss. Hileni   \n",
       "1305       3         0                            Zabour, Miss. Thamine   \n",
       "1306       3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307       3         0                              Zakarian, Mr. Ortin   \n",
       "1308       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked  boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S     2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S    11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...   ...   \n",
       "1304  female  14.5000      1      0    2665   14.4542     None        C  None   \n",
       "1305  female      NaN      1      0    2665   14.4542     None        C  None   \n",
       "1306    male  26.5000      0      0    2656    7.2250     None        C  None   \n",
       "1307    male  27.0000      0      0    2670    7.2250     None        C  None   \n",
       "1308    male  29.0000      0      0  315082    7.8750     None        S  None   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1304  328.0                             None  \n",
       "1305    NaN                             None  \n",
       "1306  304.0                             None  \n",
       "1307    NaN                             None  \n",
       "1308    NaN                             None  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titanic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 1309 entries, 0 to 1308\n",
      "Data columns (total 14 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   pclass     1309 non-null   int64  \n",
      " 1   survived   1309 non-null   int64  \n",
      " 2   name       1309 non-null   object \n",
      " 3   sex        1309 non-null   object \n",
      " 4   age        1046 non-null   float64\n",
      " 5   sibsp      1309 non-null   int64  \n",
      " 6   parch      1309 non-null   int64  \n",
      " 7   ticket     1309 non-null   object \n",
      " 8   fare       1308 non-null   float64\n",
      " 9   cabin      295 non-null    object \n",
      " 10  embarked   1307 non-null   object \n",
      " 11  boat       486 non-null    object \n",
      " 12  body       121 non-null    float64\n",
      " 13  home.dest  745 non-null    object \n",
      "dtypes: float64(3), int64(4), object(7)\n",
      "memory usage: 153.4+ KB\n"
     ]
    }
   ],
   "source": [
    "titanic.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We can delete the created json again\n",
    "os.remove(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = os.path.join(\"..\", \"..\", \"_data\", \"titanic.csv\")\n",
    "\n",
    "# In the case of a csv file, which occurs most often, we have a lot of possibilities\n",
    "titanic.to_csv(path, sep=',', decimal='.', index=False, header=True) # and many more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Aufgabe:\n",
    "Laden Sie das *Titanic* Dataset erneut (Falls Link benötigt wird: https://raw.githubusercontent.com/rolandmueller/titanic/main/titanic3.csv).\n",
    "\n",
    "Bearbeiten Sie nun folgende Punkte! Dokumentieren Sie dabei ihre Schritte indem Sie ggf. auch Fehlversuche als Zellen zu belassen (um zu zeigen, dass etwas nicht funktioniert). \n",
    "\n",
    "* Wie ist das Dataset aufgebaut?\n",
    "\n",
    "    Ein Datensatz hat (name, alter, kabine, etc.) und ob diese person überlebt hat.\n",
    "* Was bedeuten die einzelnen Features?\n",
    "\n",
    "    Es gibt personen mit (name, alter, etc.) und ob diese Personen überlebt haben.\n",
    "* Extrahieren Sie Informationen über das Dataframe über die `info()` Methoden\n",
    "\n",
    "    Namen sind Objects und bei body gibt es die wenigsten non-nulls\n",
    "* Analysieren Sie die Datentypen und auch die Anzahl der leeren Zellen in jeder Spalte. Wie viele Prozent sind leer/fehlend?\n",
    "\n",
    "    In body gibt es 90.7% NaN werte\n",
    "* Filtern sie das Dataframe, sodass es nur Zeilen beinhaltet, bei der die `Geschlecht`-Spalte und bei der das `Alter` nicht leer ist\n",
    "\n",
    "    Fertig!\n",
    "* Sortieren Sie das Dataframe absteigend nach der Spalte `Alter`\n",
    "\n",
    "    Fertig!\n",
    "* Erstellen Sie ein neues Dataframe (`inplace=False`), wo Sie den Namen außerdem noch alphabetisch sortieren (aufsteigend). Es soll also zuerst absteigend nach `Alter`, danach aufsteigend nach `Name` sortiert werden.\n",
    "\n",
    "    Fertig!\n",
    "* Speichern Sie dieses neue Dataframe unter einem neuen Namen ab und verwenden Sie ab jetzt nur noch dieses Dataset.\n",
    "\n",
    "    Fertig!\n",
    "* Verwenden Sie die anschließend einen Befehl um die Ticket-Klasse `pclass` der jüngste(n) Passagier(in) herauszufinden und außerdem, ob diese Person überlebt hat. Sollte dieser Wert <em>leer</em> sein, so dürfen Sie diese Zeilen entfernen. Wie alt war diese Person?\n",
    "\n",
    "    Age: 0.1667\n",
    "    pclass: 3\n",
    "    survived: 1\n",
    "* Bonus: Finden Sie, unabhängig von den vorigen Aufgaben, den längsten Namen (Anzahl der Charakter). Wie viele Zeichen hat dieser Name?\n",
    "\n",
    "    Length: 82\n",
    "    Name: 'Penasco y Castellana, Mrs. Victor de Satode (Maria Josefa Perez de Soto y Vallejo)'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 1309 entries, 0 to 1308\n",
      "Data columns (total 14 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   pclass     1309 non-null   int64  \n",
      " 1   survived   1309 non-null   int64  \n",
      " 2   name       1309 non-null   object \n",
      " 3   sex        1309 non-null   object \n",
      " 4   age        1046 non-null   float64\n",
      " 5   sibsp      1309 non-null   int64  \n",
      " 6   parch      1309 non-null   int64  \n",
      " 7   ticket     1309 non-null   object \n",
      " 8   fare       1308 non-null   float64\n",
      " 9   cabin      295 non-null    object \n",
      " 10  embarked   1307 non-null   object \n",
      " 11  boat       486 non-null    object \n",
      " 12  body       121 non-null    float64\n",
      " 13  home.dest  745 non-null    object \n",
      "dtypes: float64(3), int64(4), object(7)\n",
      "memory usage: 153.4+ KB\n"
     ]
    }
   ],
   "source": [
    "#Aufgabe 3\n",
    "titanic.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NULL percent of column body:  90.75630252100841 %\n",
      "NULL absolute of column body:  1188\n"
     ]
    }
   ],
   "source": [
    "#Aufgabe 4\n",
    "column = 'body'\n",
    "\n",
    "amount_null = titanic.filter([column]).isnull().sum() / len(titanic) * 100\n",
    "amount_null_count = titanic.filter([column]).isnull().sum()\n",
    "\n",
    "\n",
    "print(f'NULL percent of column {column}: ', amount_null.iloc[0], '%')\n",
    "print(f'NULL absolute of column {column}: ', amount_null_count.iloc[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Youseff, Mr. Gerious</td>\n",
       "      <td>male</td>\n",
       "      <td>45.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2628</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>312.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Hileni</td>\n",
       "      <td>female</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>328.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1306</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Mapriededer</td>\n",
       "      <td>male</td>\n",
       "      <td>26.5000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2656</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>304.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1307</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zakarian, Mr. Ortin</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2670</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1308</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zimmerman, Mr. Leo</td>\n",
       "      <td>male</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>315082</td>\n",
       "      <td>7.8750</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1046 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                             name  \\\n",
       "0          1         1                    Allen, Miss. Elisabeth Walton   \n",
       "1          1         1                   Allison, Master. Hudson Trevor   \n",
       "2          1         0                     Allison, Miss. Helen Loraine   \n",
       "3          1         0             Allison, Mr. Hudson Joshua Creighton   \n",
       "4          1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)   \n",
       "...      ...       ...                                              ...   \n",
       "1301       3         0                             Youseff, Mr. Gerious   \n",
       "1304       3         0                             Zabour, Miss. Hileni   \n",
       "1306       3         0                        Zakarian, Mr. Mapriededer   \n",
       "1307       3         0                              Zakarian, Mr. Ortin   \n",
       "1308       3         0                               Zimmerman, Mr. Leo   \n",
       "\n",
       "         sex      age  sibsp  parch  ticket      fare    cabin embarked  boat  \\\n",
       "0     female  29.0000      0      0   24160  211.3375       B5        S     2   \n",
       "1       male   0.9167      1      2  113781  151.5500  C22 C26        S    11   \n",
       "2     female   2.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "3       male  30.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "4     female  25.0000      1      2  113781  151.5500  C22 C26        S  None   \n",
       "...      ...      ...    ...    ...     ...       ...      ...      ...   ...   \n",
       "1301    male  45.5000      0      0    2628    7.2250     None        C  None   \n",
       "1304  female  14.5000      1      0    2665   14.4542     None        C  None   \n",
       "1306    male  26.5000      0      0    2656    7.2250     None        C  None   \n",
       "1307    male  27.0000      0      0    2670    7.2250     None        C  None   \n",
       "1308    male  29.0000      0      0  315082    7.8750     None        S  None   \n",
       "\n",
       "       body                        home.dest  \n",
       "0       NaN                     St Louis, MO  \n",
       "1       NaN  Montreal, PQ / Chesterville, ON  \n",
       "2       NaN  Montreal, PQ / Chesterville, ON  \n",
       "3     135.0  Montreal, PQ / Chesterville, ON  \n",
       "4       NaN  Montreal, PQ / Chesterville, ON  \n",
       "...     ...                              ...  \n",
       "1301  312.0                             None  \n",
       "1304  328.0                             None  \n",
       "1306  304.0                             None  \n",
       "1307    NaN                             None  \n",
       "1308    NaN                             None  \n",
       "\n",
       "[1046 rows x 14 columns]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Aufgabe 5\n",
    "cleaned_df_2 = titanic.dropna(subset=['sex', 'age'])\n",
    "cleaned_df_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Aufgabe 6\n",
    "titanic.sort_values('age', ascending=False, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Barkworth, Mr. Algernon Henry Wilson</td>\n",
       "      <td>male</td>\n",
       "      <td>80.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>27042</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>A23</td>\n",
       "      <td>S</td>\n",
       "      <td>B</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Hessle, Yorks</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cavendish, Mrs. Tyrell William (Julia Florence...</td>\n",
       "      <td>female</td>\n",
       "      <td>76.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>19877</td>\n",
       "      <td>78.8500</td>\n",
       "      <td>C46</td>\n",
       "      <td>S</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Little Onn Hall, Staffs</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1235</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Svensson, Mr. Johan</td>\n",
       "      <td>male</td>\n",
       "      <td>74.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>347060</td>\n",
       "      <td>7.7750</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Artagaveytia, Mr. Ramon</td>\n",
       "      <td>male</td>\n",
       "      <td>71.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17609</td>\n",
       "      <td>49.5042</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>22.0</td>\n",
       "      <td>Montevideo, Uruguay</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Goldschmidt, Mr. George B</td>\n",
       "      <td>male</td>\n",
       "      <td>71.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17754</td>\n",
       "      <td>34.6542</td>\n",
       "      <td>A5</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>New York, NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Yousif, Mr. Wazli</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2647</td>\n",
       "      <td>7.2250</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Yousseff, Mr. Gerious</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2627</td>\n",
       "      <td>14.4583</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>Zabour, Miss. Thamine</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2665</td>\n",
       "      <td>14.4542</td>\n",
       "      <td>None</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1262</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>van Billiard, Master. James William</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>A/5. 851</td>\n",
       "      <td>14.5000</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1268</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>van Melkebeke, Mr. Philemon</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>345777</td>\n",
       "      <td>9.5000</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1309 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pclass  survived                                               name  \\\n",
       "14         1         1               Barkworth, Mr. Algernon Henry Wilson   \n",
       "61         1         1  Cavendish, Mrs. Tyrell William (Julia Florence...   \n",
       "1235       3         0                                Svensson, Mr. Johan   \n",
       "9          1         0                            Artagaveytia, Mr. Ramon   \n",
       "135        1         0                          Goldschmidt, Mr. George B   \n",
       "...      ...       ...                                                ...   \n",
       "1302       3         0                                  Yousif, Mr. Wazli   \n",
       "1303       3         0                              Yousseff, Mr. Gerious   \n",
       "1305       3         0                              Zabour, Miss. Thamine   \n",
       "1262       3         0                van Billiard, Master. James William   \n",
       "1268       3         0                        van Melkebeke, Mr. Philemon   \n",
       "\n",
       "         sex   age  sibsp  parch    ticket     fare cabin embarked  boat  \\\n",
       "14      male  80.0      0      0     27042  30.0000   A23        S     B   \n",
       "61    female  76.0      1      0     19877  78.8500   C46        S     6   \n",
       "1235    male  74.0      0      0    347060   7.7750  None        S  None   \n",
       "9       male  71.0      0      0  PC 17609  49.5042  None        C  None   \n",
       "135     male  71.0      0      0  PC 17754  34.6542    A5        C  None   \n",
       "...      ...   ...    ...    ...       ...      ...   ...      ...   ...   \n",
       "1302    male   NaN      0      0      2647   7.2250  None        C  None   \n",
       "1303    male   NaN      0      0      2627  14.4583  None        C  None   \n",
       "1305  female   NaN      1      0      2665  14.4542  None        C  None   \n",
       "1262    male   NaN      1      1  A/5. 851  14.5000  None        S  None   \n",
       "1268    male   NaN      0      0    345777   9.5000  None        S  None   \n",
       "\n",
       "      body                home.dest  \n",
       "14     NaN            Hessle, Yorks  \n",
       "61     NaN  Little Onn Hall, Staffs  \n",
       "1235   NaN                     None  \n",
       "9     22.0      Montevideo, Uruguay  \n",
       "135    NaN             New York, NY  \n",
       "...    ...                      ...  \n",
       "1302   NaN                     None  \n",
       "1303   NaN                     None  \n",
       "1305   NaN                     None  \n",
       "1262   NaN                     None  \n",
       "1268   NaN                     None  \n",
       "\n",
       "[1309 rows x 14 columns]"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Aufgabe 7\n",
    "titanic_sorted_name = titanic.sort_values(['age', 'name'], ascending=[False, True], inplace=False)\n",
    "titanic_sorted_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\flori\\AppData\\Local\\Temp\\ipykernel_8412\\4067016626.py:3: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  temp.sort_values('age', ascending=True, inplace=True)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "pclass                                             3\n",
       "survived                                           1\n",
       "name         Dean, Miss. Elizabeth Gladys \"Millvina\"\n",
       "sex                                           female\n",
       "age                                           0.1667\n",
       "sibsp                                              1\n",
       "parch                                              2\n",
       "ticket                                     C.A. 2315\n",
       "fare                                          20.575\n",
       "cabin                                           None\n",
       "embarked                                           S\n",
       "boat                                              10\n",
       "body                                             NaN\n",
       "home.dest                 Devon, England Wichita, KS\n",
       "Name: 763, dtype: object"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Aufgabe 8\n",
    "temp = titanic_sorted_name.dropna(subset=['age'])\n",
    "temp.sort_values('age', ascending=True, inplace=True)\n",
    "temp.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "82"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Bonus\n",
    "lengths = titanic_sorted_name['name'].apply(len)\n",
    "longest_name = titanic_sorted_name.loc[lengths.idxmax(), 'name']\n",
    "longest_name_length = lengths.max()\n",
    "longest_name_length\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dsai",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
