ruality analysis . updated databases
This commit is contained in:
1888
analysis/new analysis Aug 2025/analysis10-2021.ipynb
Normal file
1888
analysis/new analysis Aug 2025/analysis10-2021.ipynb
Normal file
File diff suppressed because one or more lines are too long
BIN
analysis/new analysis Aug 2025/analysis10-2021.pdf
Normal file
BIN
analysis/new analysis Aug 2025/analysis10-2021.pdf
Normal file
Binary file not shown.
80
analysis/new analysis Aug 2025/analysis11-ruca_2021.ipynb
Normal file
80
analysis/new analysis Aug 2025/analysis11-ruca_2021.ipynb
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "00abdbfd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Colorado Spills Project\n",
|
||||
"### incorporating rurality data\n",
|
||||
"### Date: 2025-08-06\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "3dc76f74",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import geopandas as gpd\n",
|
||||
"import statsmodels.formula.api as smf\n",
|
||||
"from sqlalchemy import create_engine\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"\n",
|
||||
"# Connect to your database\n",
|
||||
"engine = create_engine(f\"postgresql+psycopg2://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_HOST')}:{os.getenv('DB_PORT')}/colorado_spills\")\n",
|
||||
"\n",
|
||||
"# Load data with geometry preserved\n",
|
||||
"spills = gpd.read_postgis(\"SELECT * FROM spills_with_ruca\", engine, geom_col='geometry')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "7e7219b8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def classify_rurality(ruca_code):\n",
|
||||
" if pd.isna(ruca_code):\n",
|
||||
" return 'Unknown'\n",
|
||||
" elif ruca_code <= 3:\n",
|
||||
" return 'Urban'\n",
|
||||
" elif ruca_code <= 6:\n",
|
||||
" return 'Suburban'\n",
|
||||
" else:\n",
|
||||
" return 'Rural'\n",
|
||||
"\n",
|
||||
"spills['ruca_code'] = pd.to_numeric(spills['ruca_code'], errors='coerce')\n",
|
||||
"spills['rurality'] = spills['ruca_code'].apply(classify_rurality)\n",
|
||||
"spills = spills[spills['rurality'] != 'Unknown'] # drop unknowns\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "base",
|
||||
"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.12.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user