{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"id": "0f3a8346-0c49-4cab-ab0a-e982006db476",
"metadata": {},
"outputs": [],
"source": [
"import ibis\n",
"from ibis import _\n",
"\n",
"con = ibis.duckdb.connect()\n",
"\n",
"df = (con.\n",
" read_csv(\"landvote.csv\")\n",
" .mutate(amount = _[\"Conservation Funds Approved\"])\n",
" .mutate(conservation_funds_approved=_.amount.replace('$', '').replace(',', '').cast('float'))\n",
" .mutate(year = _.Date.year())\n",
" )\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b36f93ae-b12b-46ed-a105-07243b86b308",
"metadata": {},
"outputs": [],
"source": [
"cols = ['State',\n",
" 'Jurisdiction Name',\n",
" 'Jurisdiction Type',\n",
" 'Date',\n",
" 'Description',\n",
" 'Finance Mechanism',\n",
" '\"Other\" Comment',\n",
" 'Purpose',\n",
" 'Conservation Funds at Stake',\n",
" 'Pass?',\n",
" 'Status',\n",
" '% Yes',\n",
" '% No',\n",
" 'Notes',\n",
" 'Voted Acq. Measure',\n",
" 'amount',\n",
" 'conservation_funds_approved',\n",
" 'year']\n",
"\n",
"df.select(cols).to_csv(\"data.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "15dda23e-4db4-4860-9c48-20ce580d635b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" State | \n",
" n | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" CA | \n",
" 1.907187e+10 | \n",
"
\n",
" \n",
" 1 | \n",
" FL | \n",
" 1.411086e+10 | \n",
"
\n",
" \n",
" 2 | \n",
" NJ | \n",
" 1.223420e+10 | \n",
"
\n",
" \n",
" 3 | \n",
" CO | \n",
" 6.011241e+09 | \n",
"
\n",
" \n",
" 4 | \n",
" MN | \n",
" 5.963134e+09 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" State n\n",
"0 CA 1.907187e+10\n",
"1 FL 1.411086e+10\n",
"2 NJ 1.223420e+10\n",
"3 CO 6.011241e+09\n",
"4 MN 5.963134e+09"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.group_by(_.State).agg(n = _.conservation_funds_approved.sum()).order_by(_.n.desc()).head().execute()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "1117dd18-5207-4e14-9920-4feb262d373c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" State | \n",
" n | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" MA | \n",
" 132 | \n",
"
\n",
" \n",
" 1 | \n",
" NJ | \n",
" 128 | \n",
"
\n",
" \n",
" 2 | \n",
" CO | \n",
" 47 | \n",
"
\n",
" \n",
" 3 | \n",
" CA | \n",
" 47 | \n",
"
\n",
" \n",
" 4 | \n",
" IL | \n",
" 37 | \n",
"
\n",
" \n",
" 5 | \n",
" PA | \n",
" 35 | \n",
"
\n",
" \n",
" 6 | \n",
" WA | \n",
" 34 | \n",
"
\n",
" \n",
" 7 | \n",
" OH | \n",
" 26 | \n",
"
\n",
" \n",
" 8 | \n",
" MI | \n",
" 23 | \n",
"
\n",
" \n",
" 9 | \n",
" FL | \n",
" 19 | \n",
"
\n",
" \n",
" 10 | \n",
" Ore | \n",
" 15 | \n",
"
\n",
" \n",
" 11 | \n",
" NC | \n",
" 13 | \n",
"
\n",
" \n",
" 12 | \n",
" CT | \n",
" 13 | \n",
"
\n",
" \n",
" 13 | \n",
" NY | \n",
" 12 | \n",
"
\n",
" \n",
" 14 | \n",
" TX | \n",
" 11 | \n",
"
\n",
" \n",
" 15 | \n",
" GA | \n",
" 9 | \n",
"
\n",
" \n",
" 16 | \n",
" AZ | \n",
" 9 | \n",
"
\n",
" \n",
" 17 | \n",
" MN | \n",
" 7 | \n",
"
\n",
" \n",
" 18 | \n",
" UT | \n",
" 7 | \n",
"
\n",
" \n",
" 19 | \n",
" WI | \n",
" 6 | \n",
"
\n",
" \n",
" 20 | \n",
" AK | \n",
" 5 | \n",
"
\n",
" \n",
" 21 | \n",
" NV | \n",
" 4 | \n",
"
\n",
" \n",
" 22 | \n",
" VA | \n",
" 4 | \n",
"
\n",
" \n",
" 23 | \n",
" ID | \n",
" 4 | \n",
"
\n",
" \n",
" 24 | \n",
" MT | \n",
" 4 | \n",
"
\n",
" \n",
" 25 | \n",
" NM | \n",
" 3 | \n",
"
\n",
" \n",
" 26 | \n",
" ME | \n",
" 3 | \n",
"
\n",
" \n",
" 27 | \n",
" OK | \n",
" 2 | \n",
"
\n",
" \n",
" 28 | \n",
" RI | \n",
" 2 | \n",
"
\n",
" \n",
" 29 | \n",
" LA | \n",
" 2 | \n",
"
\n",
" \n",
" 30 | \n",
" AR | \n",
" 2 | \n",
"
\n",
" \n",
" 31 | \n",
" MS | \n",
" 2 | \n",
"
\n",
" \n",
" 32 | \n",
" SC | \n",
" 2 | \n",
"
\n",
" \n",
" 33 | \n",
" ND | \n",
" 1 | \n",
"
\n",
" \n",
" 34 | \n",
" TN | \n",
" 1 | \n",
"
\n",
" \n",
" 35 | \n",
" NE | \n",
" 1 | \n",
"
\n",
" \n",
" 36 | \n",
" IA | \n",
" 1 | \n",
"
\n",
" \n",
" 37 | \n",
" KY | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" State n\n",
"0 MA 132\n",
"1 NJ 128\n",
"2 CO 47\n",
"3 CA 47\n",
"4 IL 37\n",
"5 PA 35\n",
"6 WA 34\n",
"7 OH 26\n",
"8 MI 23\n",
"9 FL 19\n",
"10 Ore 15\n",
"11 NC 13\n",
"12 CT 13\n",
"13 NY 12\n",
"14 TX 11\n",
"15 GA 9\n",
"16 AZ 9\n",
"17 MN 7\n",
"18 UT 7\n",
"19 WI 6\n",
"20 AK 5\n",
"21 NV 4\n",
"22 VA 4\n",
"23 ID 4\n",
"24 MT 4\n",
"25 NM 3\n",
"26 ME 3\n",
"27 OK 2\n",
"28 RI 2\n",
"29 LA 2\n",
"30 AR 2\n",
"31 MS 2\n",
"32 SC 2\n",
"33 ND 1\n",
"34 TN 1\n",
"35 NE 1\n",
"36 IA 1\n",
"37 KY 1"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.filter(_.Status == \"Fail\").group_by(_.State).agg(n = _.count()).order_by(_.n.desc()).execute()"
]
}
],
"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
}