Commit 63248d6b authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Update analysis

parent 1717b4a7
......@@ -9,3 +9,4 @@ latex/bare_jrnl.synctex.gz
latex/bare_jrnl.pdf
latex/bare_jrnl.log
latex/bare_jrnl.bbl
.ipynb_checkpoints
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
......@@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
......@@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
......@@ -48,7 +48,7 @@
"df_counts[\"id\"] = df_counts[\"id\"].fillna(method = \"pad\").astype(np.int)\n",
"df_counts = df_counts[df_counts[\"slot\"].str.startswith(\"DWV\")]\n",
"\n",
"df_counts[\"freight\"] = df_counts[\"slot\"] == \"DWV SGF\"\n",
"df_counts[\"freight\"] = (df_counts[\"slot\"] == \"DWV SGF\") | (df_counts[\"slot\"] == \"DWV SV\")\n",
"df_counts = df_counts.drop(columns = [\"slot\"])\n",
"df_counts = df_counts.groupby([\"id\", \"freight\"]).sum().reset_index()\n",
"\n",
......@@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
......
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import shapely.geometry as geo
import geopandas as gpd
%matplotlib inline
```
%% Cell type:code id: tags:
``` python
df_locations = pd.read_excel("messstellenverzeichnis.xlsx", skiprows = 6).rename({
"Zählstellen-Bezeichnung": "name",
"Nr": "id", "Koordinate Ost": "x", "Koordinate Nord": "y"
}, axis = 1)[["id", "name", "x", "y"]].set_index("id")
df_locations["geometry"] = [geo.Point(*p) for p in zip(df_locations["x"], df_locations["y"])]
df_locations = gpd.GeoDataFrame(df_locations)
df_locations.crs = {"init": "EPSG:21781"}
df_locations = df_locations.to_crs({"init": "EPSG:2056"})
df_locations = df_locations[["name", "geometry"]]
```
%% Cell type:code id: tags:
``` python
df_counts = pd.read_excel(
"Jahresergebnisse-2017.xlsx",
skiprows = 7, sheet_name = "Klassendaten", usecols = [0, 5, 23],
names = ["id", "slot", "count"]
)
df_counts["id"] = df_counts["id"].fillna(method = "pad").astype(np.int)
df_counts = df_counts[df_counts["slot"].str.startswith("DWV")]
df_counts["freight"] = df_counts["slot"] == "DWV SGF"
df_counts["freight"] = (df_counts["slot"] == "DWV SGF") | (df_counts["slot"] == "DWV SV")
df_counts = df_counts.drop(columns = ["slot"])
df_counts = df_counts.groupby(["id", "freight"]).sum().reset_index()
df_total = df_counts[~df_counts["freight"]][["id", "count"]].rename({"count": "total_count"}, axis = 1)
df_freight = df_counts[df_counts["freight"]][["id", "count"]].rename({"count": "freight_count"}, axis = 1)
df_counts = pd.merge(df_total, df_freight, how = "left", on = "id")
assert(len(df_counts) == len(df_counts["id"].unique()))
df_counts["personal_count"] = df_counts["total_count"] - df_counts["freight_count"]
df_counts = df_counts[df_counts["total_count"] > 0]
df_counts = df_counts.set_index("id")
```
%% Cell type:code id: tags:
``` python
df = pd.concat([df_locations, df_counts], axis = 1).dropna()
df.reset_index().to_file("astra_count_stations.geojson", driver = "GeoJSON")
```
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment