{
"cells": [
{
"cell_type": "code",
"execution_count": 21,
"id": "b313a218-4778-4d5b-9036-f0370d4212a0",
"metadata": {},
"outputs": [],
"source": [
"import ibis\n",
"from ibis import _\n",
"conn = ibis.duckdb.connect()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "fbbd28ea-f1e3-4f3d-ab99-a2ae9b04f3d4",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"state_boundaries = \"https://data.source.coop/cboettig/us-boundaries/us-state-territory.parquet\"\n",
"county_boundaries = \"https://data.source.coop/cboettig/us-boundaries/us-county.parquet\"\n",
"\n",
"states = conn.read_parquet(state_boundaries).rename(State = \"STUSPS\")\n",
"county = conn.read_parquet(county_boundaries).rename(county = \"NAMELSAD\")\n",
"\n",
"votes = conn.read_csv(\"measures.csv\")\n"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "0f818c94-af17-46a2-b47f-a729de75bd63",
"metadata": {},
"outputs": [],
"source": [
"gdf = (votes\n",
" .filter(votes[\"Jurisdiction Type\"] == \"County\")\n",
" .rename(county = \"Jurisdiction Name\")\n",
" .join(county, \"county\")\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "7729130e-7d0f-4b0e-b676-073643556134",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "afb9c4f5e69440e18ee15b7e73ae7dad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"polygons = gdf.head().execute().set_crs(\"epsg:4326\")\n"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "fa397626-6e94-4ab9-a3bb-2bcbd14e8d40",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ccfd3dc22e74b078af4df85f4a7ead0",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"Map(height='600px', map_options={'bearing': 0, 'center': (0, 20), 'pitch': 0, 'style': 'https://tiles.openfreeā¦"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import leafmap.maplibregl as leafmap\n",
"outcome = {\n",
" 'fill-color': [\n",
" 'match',\n",
" ['get', 'Pass?'], \n",
" \"True\", '#00FF00',\n",
" \"False\", '#FFA07A', \n",
" '#ccc'\n",
" ],\n",
"}\n",
"paint = {\"fill-color\": \"#00FF00\", \"fill-opacity\": 0.5 }\n",
"m = leafmap.Map(style=\"positron\")\n",
"m.add_gdf(polygons,\"fill\")\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "3b9f4c6b-c1d5-4750-80e0-d94ea047b8da",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"polygons.geometry.iloc[1]"
]
}
],
"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.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}