Skip to content

Instantly share code, notes, and snippets.

@johanvdw
Created November 28, 2017 15:11
Show Gist options
  • Save johanvdw/5f02dcb907578d248aa2613d98caef44 to your computer and use it in GitHub Desktop.
Save johanvdw/5f02dcb907578d248aa2613d98caef44 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>grondwaterlocatie</th>\n",
" <th>filternummer</th>\n",
" <th>meetnet</th>\n",
" <th>aquifer</th>\n",
" <th>regime</th>\n",
" <th>diepte_onderkant_filter</th>\n",
" <th>lengte_filter</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1-0709</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0254</td>\n",
" <td>freatisch</td>\n",
" <td>8.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1-0709</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>0400</td>\n",
" <td>niet-freatisch</td>\n",
" <td>52.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1-0709</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>0502</td>\n",
" <td>niet-freatisch</td>\n",
" <td>71.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1-0709</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0504</td>\n",
" <td>niet-freatisch</td>\n",
" <td>87.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1-0709</td>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" <td>0612</td>\n",
" <td>niet-freatisch</td>\n",
" <td>108.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" grondwaterlocatie filternummer meetnet aquifer regime \\\n",
"0 1-0709 1 1 0254 freatisch \n",
"1 1-0709 2 1 0400 niet-freatisch \n",
"2 1-0709 3 1 0502 niet-freatisch \n",
"3 1-0709 4 1 0504 niet-freatisch \n",
"4 1-0709 5 1 0612 niet-freatisch \n",
"\n",
" diepte_onderkant_filter lengte_filter \n",
"0 8.00 2.0 \n",
"1 52.00 2.0 \n",
"2 71.00 2.0 \n",
"3 87.00 2.0 \n",
"4 108.00 2.0 "
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import xml.etree.ElementTree as ET\n",
"import pandas as pd\n",
"ET.register_namespace('kern', 'http://kern.schemas.dov.vlaanderen.be')\n",
"tree = ET.parse(\"../tests/data/1-0709.xml\")\n",
"\n",
"filters = tree.findall(\"./filter\")\n",
"\n",
"\n",
"def get_filterlengte (opbouw): \n",
" tot = opbouw.find(\"./onderdeel[filterelement='filter']/tot\").text\n",
" van = opbouw.find(\"./onderdeel[filterelement='filter']/van\").text\n",
" return float(tot) - float(van)\n",
"\n",
"tl = [(f.find(\"grondwaterlocatie\").text,\n",
" f.find(\"identificatie\").text,\n",
" f.find(\"meetnet\").text,\n",
" f.find(\"ligging/aquifer\").text,\n",
" f.find(\"ligging/regime\").text,\n",
" f.find(\"opbouw\").find(\"./onderdeel[filterelement='filter']/tot\").text,\n",
" get_filterlengte(f.find(\"opbouw\"))\n",
" ) for f in filters]\n",
"\n",
"columns = [\"grondwaterlocatie\", \"filternummer\", \"meetnet\", \n",
" \"aquifer\", \"regime\", \"diepte_onderkant_filter\", \"lengte_filter\"]\n",
"filters_df = pd.DataFrame(tl, columns = columns)\n",
"\n",
"filters_df"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>grondwaterlocatie</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" grondwaterlocatie x y\n",
"0 1-0709 152249.0 200614.0"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gwl = tree.findall(\"./grondwaterlocatie\")\n",
"tg = [(g.find(\"identificatie\").text,\n",
" g.find(\"puntligging/xy/x\").text,\n",
" g.find(\"puntligging/xy/y\").text\n",
" ) for g in gwl]\n",
"\n",
"columns = [\"grondwaterlocatie\",\"x\",\"y\"]\n",
"gwl_df = pd.DataFrame(tg, columns = columns)\n",
"gwl_df"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>grondwaterlocatie</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" <th>filternummer</th>\n",
" <th>meetnet</th>\n",
" <th>aquifer</th>\n",
" <th>regime</th>\n",
" <th>diepte_onderkant_filter</th>\n",
" <th>lengte_filter</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0254</td>\n",
" <td>freatisch</td>\n",
" <td>8.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>0400</td>\n",
" <td>niet-freatisch</td>\n",
" <td>52.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>0502</td>\n",
" <td>niet-freatisch</td>\n",
" <td>71.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0504</td>\n",
" <td>niet-freatisch</td>\n",
" <td>87.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1-0709</td>\n",
" <td>152249.0</td>\n",
" <td>200614.0</td>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" <td>0612</td>\n",
" <td>niet-freatisch</td>\n",
" <td>108.00</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" grondwaterlocatie x y filternummer meetnet aquifer \\\n",
"0 1-0709 152249.0 200614.0 1 1 0254 \n",
"1 1-0709 152249.0 200614.0 2 1 0400 \n",
"2 1-0709 152249.0 200614.0 3 1 0502 \n",
"3 1-0709 152249.0 200614.0 4 1 0504 \n",
"4 1-0709 152249.0 200614.0 5 1 0612 \n",
"\n",
" regime diepte_onderkant_filter lengte_filter \n",
"0 freatisch 8.00 2.0 \n",
"1 niet-freatisch 52.00 2.0 \n",
"2 niet-freatisch 71.00 2.0 \n",
"3 niet-freatisch 87.00 2.0 \n",
"4 niet-freatisch 108.00 2.0 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gwl_df.merge(filters_df, on=\"grondwaterlocatie\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment