{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b3043fed",
   "metadata": {},
   "source": [
    "Notebook for Sectio Data Exploration for now"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8bd3a795",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f494928",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_147454/1144322908.py:1: DtypeWarning: Columns (19,20) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  df = pd.read_csv(\"../data/sectio_cesarea/cesarean_section.csv\", delimiter=\";\")\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 62184 characters]",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df = pd.read_csv(\"../data/sectio_cesarea/cesarean_section.csv\", delimiter=\";\")\n",
    "df[\"ANO_MES_EVENTO\"] = pd.to_datetime(df[\"ANO_MES_EVENTO\"])\n",
    "\n",
    "events_per_month = df.groupby(\"ANO_MES_EVENTO\")[\"ID_EVENTO_ATENCAO_SAUDE\"].nunique()\n",
    "\n",
    "plt.figure(figsize=(10,4))\n",
    "sns.lineplot(x=events_per_month.index, y=events_per_month.values)\n",
    "plt.title(\"Anzahl Ereignisse pro Monat\")\n",
    "plt.xlabel(\"Monat\")\n",
    "plt.ylabel(\"Anzahl Ereignisse\")\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd5d2ac9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32532 characters]",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(10,4))\n",
    "sns.histplot(data=df[df[\"TEMPO_DE_PERMANENCIA\"] >= 0], \n",
    "             x=\"TEMPO_DE_PERMANENCIA\", bins=50)\n",
    "plt.xlim(0, 30)  # z.B. auf 30 Tage begrenzen, um den \"Kern\" zu sehen\n",
    "plt.title(\"Verteilung der Aufenthaltsdauer (in Tagen, gekappt auf 30)\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d680e91f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33412 characters]",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 25992 characters]",
      "text/plain": [
       "<Figure size 500x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.figure(figsize=(10,4))\n",
    "sns.countplot(data=df, x=\"FAIXA_ETARIA\",\n",
    "              order=df[\"FAIXA_ETARIA\"].value_counts().index)\n",
    "plt.xticks(rotation=45)\n",
    "plt.title(\"Verteilung der Altersgruppen\")\n",
    "plt.show()\n",
    "\n",
    "plt.figure(figsize=(5,4))\n",
    "sns.countplot(data=df, x=\"SEXO_BENEFICIARIO\")\n",
    "plt.title(\"Verteilung nach Geschlecht\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ed4f6311",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42920 characters]",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.figure(figsize=(10,4))\n",
    "sns.boxplot(data=df[df[\"TEMPO_DE_PERMANENCIA\"] >= 0],\n",
    "            x=\"FAIXA_ETARIA\", y=\"TEMPO_DE_PERMANENCIA\")\n",
    "plt.xticks(rotation=45)\n",
    "plt.title(\"Aufenthaltsdauer nach Altersgruppe\")\n",
    "plt.ylim(0, 20)  # für Übersicht evtl. begrenzen\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "project",
   "language": "python",
   "name": "project"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
