updating
This commit is contained in:
101
src/Intensivstationen.ipynb
Normal file
101
src/Intensivstationen.ipynb
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9de5907f-18f5-4cb1-903e-26028ff1fa03",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"pd.set_option('display.max_rows', 100)\n",
|
||||
"pd.set_option('display.max_columns', None)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "997a4bdb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def readTimeseries(bundesland = None):\n",
|
||||
" df = pd.read_csv(\n",
|
||||
" 'intensivstationen/zeitreihe-bundeslaender.csv',\n",
|
||||
" low_memory = False,\n",
|
||||
" parse_dates = ['Datum'],\n",
|
||||
" date_parser = lambda dateStr: pd.to_datetime(dateStr, utc = True))\n",
|
||||
" if bundesland is not None:\n",
|
||||
" return df[df['Bundesland'] == bundesland][['Datum', 'Belegte_Intensivbetten', 'Freie_Intensivbetten', '7_Tage_Notfallreserve']]\n",
|
||||
" else:\n",
|
||||
" res = df.groupby('Datum').agg(**{\n",
|
||||
" 'Belegte_Intensivbetten': pd.NamedAgg(column = 'Belegte_Intensivbetten', aggfunc = 'sum'),\n",
|
||||
" 'Freie_Intensivbetten': pd.NamedAgg(column = 'Freie_Intensivbetten', aggfunc = 'sum'),\n",
|
||||
" '7_Tage_Notfallreserve': pd.NamedAgg(column = '7_Tage_Notfallreserve', aggfunc = 'sum'), \n",
|
||||
" })\n",
|
||||
" #df = df[['Datum', 'Belegte_Intensivbetten', 'Freie_Intensivbetten', '7_Tage_Notfallreserve']]\n",
|
||||
" #res.to_csv('../docs/data/intensivstationen/data-de-generated.csv', index = True)\n",
|
||||
" return res.reset_index()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a97f5b2b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def readAndPersistTimeseries(bundesland = None):\n",
|
||||
" dataFrame = readTimeseries(bundesland)\n",
|
||||
" dataFrame.to_csv(_getFilename(bundesland), index =False)\n",
|
||||
" return dataFrame\n",
|
||||
"\n",
|
||||
"def _getFilename(bundesland):\n",
|
||||
" return '../docs/data/intensivstationen/intensivstationen{suffix}.csv'.format(suffix = '-' + bundesland if bundesland is not None else '-de')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "63ca93a4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"readAndPersistTimeseries(bundesland = 'BADEN_WUERTTEMBERG')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "349edd73",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"readAndPersistTimeseries()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user