{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Census of Agriculture - Republic of Ireland" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "from datetime import datetime, timezone\n", "import pandas as pd\n", "import pooch" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Farms with Livestock\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "URL = (\n", " \"https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadDataset/\"\n", " \"AVA42/CSV/1.0/en\"\n", ")\n", "KNOWN_HASH = None\n", "FILE_NAME = \"COA_2020_AVA42.csv\"\n", "SUB_DIR = os.path.join(\"data\", \"agricultural_census\", \"CSO\")\n", "DATA_FILE = os.path.join(SUB_DIR, FILE_NAME)\n", "os.makedirs(SUB_DIR, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# download data if necessary\n", "if not os.path.isfile(os.path.join(SUB_DIR, FILE_NAME)):\n", " pooch.retrieve(\n", " url=URL, known_hash=KNOWN_HASH, fname=FILE_NAME, path=SUB_DIR\n", " )\n", "\n", " with open(\n", " os.path.join(SUB_DIR, f\"{FILE_NAME[:-4]}.txt\"), \"w\", encoding=\"utf-8\"\n", " ) as outfile:\n", " outfile.write(\n", " f\"Data downloaded on: {datetime.now(tz=timezone.utc)}\\n\"\n", " f\"Download URL: {URL}\"\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "coa = pd.read_csv(DATA_FILE)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
STATISTICStatistic LabelTLIST(A1)Census YearC03904V04656Electoral DivisionC02148V02965Type of LivestockUNITVALUE
0COALSLivestock on Farms20002000-State1Total cattleNumber7037435
1COALSLivestock on Farms20002000-State1111Dairy cowsNumber1177452
2COALSLivestock on Farms20002000-State1112Other cowsNumber1186989
3COALSLivestock on Farms20002000-State2Total sheepNumber7555044
4COALSLivestock on Farms20002000-State9999999Livestock Units (LSU)Number5941304.7
\n", "
" ], "text/plain": [ " STATISTIC Statistic Label TLIST(A1) Census Year C03904V04656 \\\n", "0 COALS Livestock on Farms 2000 2000 - \n", "1 COALS Livestock on Farms 2000 2000 - \n", "2 COALS Livestock on Farms 2000 2000 - \n", "3 COALS Livestock on Farms 2000 2000 - \n", "4 COALS Livestock on Farms 2000 2000 - \n", "\n", " Electoral Division C02148V02965 Type of Livestock UNIT VALUE \n", "0 State 1 Total cattle Number 7037435 \n", "1 State 1111 Dairy cows Number 1177452 \n", "2 State 1112 Other cows Number 1186989 \n", "3 State 2 Total sheep Number 7555044 \n", "4 State 9999999 Livestock Units (LSU) Number 5941304.7 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coa.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# filter for 2020, for total cattle and total sheep\n", "# drop the state numbers\n", "coa = coa[coa[\"Census Year\"] == 2020]\n", "coa = coa[coa[\"Type of Livestock\"].isin([\"Total cattle\", \"Total sheep\"])]\n", "coa = coa[coa[\"Electoral Division\"] != \"State\"]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
STATISTICStatistic LabelTLIST(A1)Census YearC03904V04656Electoral DivisionC02148V02965Type of LivestockUNITVALUE
34105COALSLivestock on Farms202020203576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/080461Total cattleNumber1955
34108COALSLivestock on Farms202020203576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/080462Total sheepNumber420
34110COALSLivestock on Farms202020203576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/090351Total cattleNumber2164
34113COALSLivestock on Farms202020203576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/090352Total sheepNumber675
34115COALSLivestock on Farms202020202AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 100011Total cattleNumber0
\n", "
" ], "text/plain": [ " STATISTIC Statistic Label TLIST(A1) Census Year \\\n", "34105 COALS Livestock on Farms 2020 2020 \n", "34108 COALS Livestock on Farms 2020 2020 \n", "34110 COALS Livestock on Farms 2020 2020 \n", "34113 COALS Livestock on Farms 2020 2020 \n", "34115 COALS Livestock on Farms 2020 2020 \n", "\n", " C03904V04656 \\\n", "34105 3576C59993454152E0530100007F0280 \n", "34108 3576C59993454152E0530100007F0280 \n", "34110 3576C59992AD4152E0530100007F0280 \n", "34113 3576C59992AD4152E0530100007F0280 \n", "34115 2AE1962918C813A3E055000000000001 \n", "\n", " Electoral Division C02148V02965 \\\n", "34105 Brisha / Capard, Co.Laois, 08045/08046 1 \n", "34108 Brisha / Capard, Co.Laois, 08045/08046 2 \n", "34110 Firry / Newgrove, Co.Longford, 09024/09035 1 \n", "34113 Firry / Newgrove, Co.Longford, 09024/09035 2 \n", "34115 Fair Gate, Co.Louth, 10001 1 \n", "\n", " Type of Livestock UNIT VALUE \n", "34105 Total cattle Number 1955 \n", "34108 Total sheep Number 420 \n", "34110 Total cattle Number 2164 \n", "34113 Total sheep Number 675 \n", "34115 Total cattle Number 0 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coa.head()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# drop unnecessary columns\n", "coa.drop(\n", " columns=[\n", " \"STATISTIC\",\n", " \"Statistic Label\",\n", " \"TLIST(A1)\",\n", " \"C02148V02965\",\n", " \"UNIT\",\n", " \"Census Year\",\n", " ],\n", " inplace=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# split cattle and sheep values into separate columns\n", "coa = pd.merge(\n", " coa[coa[\"Type of Livestock\"] == \"Total cattle\"],\n", " coa[coa[\"Type of Livestock\"] == \"Total sheep\"],\n", " on=[\"C03904V04656\", \"Electoral Division\"],\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
C03904V04656Electoral DivisionType of Livestock_xVALUE_xType of Livestock_yVALUE_y
03576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/08046Total cattle1955Total sheep420
13576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/09035Total cattle2164Total sheep675
22AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 10001Total cattle0Total sheep0
32AE19629193513A3E055000000000001St. Laurence Gate, Co.Louth, 10002Total cattle0Total sheep0
42AE19629191E13A3E055000000000001West Gate, Co.Louth, 10003Total cattle0Total sheep0
\n", "
" ], "text/plain": [ " C03904V04656 \\\n", "0 3576C59993454152E0530100007F0280 \n", "1 3576C59992AD4152E0530100007F0280 \n", "2 2AE1962918C813A3E055000000000001 \n", "3 2AE19629193513A3E055000000000001 \n", "4 2AE19629191E13A3E055000000000001 \n", "\n", " Electoral Division Type of Livestock_x VALUE_x \\\n", "0 Brisha / Capard, Co.Laois, 08045/08046 Total cattle 1955 \n", "1 Firry / Newgrove, Co.Longford, 09024/09035 Total cattle 2164 \n", "2 Fair Gate, Co.Louth, 10001 Total cattle 0 \n", "3 St. Laurence Gate, Co.Louth, 10002 Total cattle 0 \n", "4 West Gate, Co.Louth, 10003 Total cattle 0 \n", "\n", " Type of Livestock_y VALUE_y \n", "0 Total sheep 420 \n", "1 Total sheep 675 \n", "2 Total sheep 0 \n", "3 Total sheep 0 \n", "4 Total sheep 0 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coa.head()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# rename columns\n", "coa.rename(\n", " columns={\n", " \"Electoral Division\": \"electoral_division\",\n", " \"VALUE_x\": \"total_cattle\",\n", " \"VALUE_y\": \"total_sheep\",\n", " },\n", " inplace=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# drop unnecessary columns\n", "coa.drop(columns=[\"Type of Livestock_x\", \"Type of Livestock_y\"], inplace=True)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
C03904V04656electoral_divisiontotal_cattletotal_sheep
03576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/080461955420
13576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/090352164675
22AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 1000100
32AE19629193513A3E055000000000001St. Laurence Gate, Co.Louth, 1000200
42AE19629191E13A3E055000000000001West Gate, Co.Louth, 1000300
\n", "
" ], "text/plain": [ " C03904V04656 \\\n", "0 3576C59993454152E0530100007F0280 \n", "1 3576C59992AD4152E0530100007F0280 \n", "2 2AE1962918C813A3E055000000000001 \n", "3 2AE19629193513A3E055000000000001 \n", "4 2AE19629191E13A3E055000000000001 \n", "\n", " electoral_division total_cattle total_sheep \n", "0 Brisha / Capard, Co.Laois, 08045/08046 1955 420 \n", "1 Firry / Newgrove, Co.Longford, 09024/09035 2164 675 \n", "2 Fair Gate, Co.Louth, 10001 0 0 \n", "3 St. Laurence Gate, Co.Louth, 10002 0 0 \n", "4 West Gate, Co.Louth, 10003 0 0 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coa.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Land Utilisation\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "URL = (\n", " \"https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadDataset/\"\n", " \"AVA44/CSV/1.0/en\"\n", ")\n", "KNOWN_HASH = None\n", "FILE_NAME = \"COA_2020_AVA44.csv\"\n", "SUB_DIR = os.path.join(\"data\", \"agricultural_census\", \"CSO\")\n", "DATA_FILE = os.path.join(SUB_DIR, FILE_NAME)\n", "os.makedirs(SUB_DIR, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading data from 'https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadDataset/AVA44/CSV/1.0/en' to file '/run/media/nms/Backup/Documents/Git/ClimAg/ClimAg/data/AgriculturalCensus/CSO/COA_2020_AVA44.csv'.\n", "SHA256 hash of downloaded file: cb5cd56a705f4dbd5561b77ca6cd20d708b9014eb5c24e75ab4123a9d8d33203\n", "Use this value as the 'known_hash' argument of 'pooch.retrieve' to ensure that the file hasn't changed if it is downloaded again in the future.\n" ] } ], "source": [ "# download data if necessary\n", "if not os.path.isfile(os.path.join(SUB_DIR, FILE_NAME)):\n", " pooch.retrieve(\n", " url=URL, known_hash=KNOWN_HASH, fname=FILE_NAME, path=SUB_DIR\n", " )\n", "\n", " with open(\n", " os.path.join(SUB_DIR, f\"{FILE_NAME[:-4]}.txt\"), \"w\", encoding=\"utf-8\"\n", " ) as outfile:\n", " outfile.write(\n", " f\"Data downloaded on: {datetime.now(tz=timezone.utc)}\\n\"\n", " f\"Download URL: {URL}\"\n", " )" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "land = pd.read_csv(DATA_FILE)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
STATISTICStatistic LabelTLIST(A1)Census YearC03904V04656Electoral DivisionC02145V02588Type of CropUNITVALUE
0COALUArea of selected crops20002000-State1Area farmed (AAU)Hectares4443071
1COALUArea of selected crops20002000-State11430Total cerealsHectares279045
2COALUArea of selected crops20002000-State11114All grasslandHectares4041947
3COALUArea of selected crops200020003576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/080461Area farmed (AAU)Hectares966.4
4COALUArea of selected crops200020003576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/0804611430Total cerealsHectares2.2
\n", "
" ], "text/plain": [ " STATISTIC Statistic Label TLIST(A1) Census Year \\\n", "0 COALU Area of selected crops 2000 2000 \n", "1 COALU Area of selected crops 2000 2000 \n", "2 COALU Area of selected crops 2000 2000 \n", "3 COALU Area of selected crops 2000 2000 \n", "4 COALU Area of selected crops 2000 2000 \n", "\n", " C03904V04656 Electoral Division \\\n", "0 - State \n", "1 - State \n", "2 - State \n", "3 3576C59993454152E0530100007F0280 Brisha / Capard, Co.Laois, 08045/08046 \n", "4 3576C59993454152E0530100007F0280 Brisha / Capard, Co.Laois, 08045/08046 \n", "\n", " C02145V02588 Type of Crop UNIT VALUE \n", "0 1 Area farmed (AAU) Hectares 4443071 \n", "1 11430 Total cereals Hectares 279045 \n", "2 11114 All grassland Hectares 4041947 \n", "3 1 Area farmed (AAU) Hectares 966.4 \n", "4 11430 Total cereals Hectares 2.2 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "land.head()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "# filter for 2020, for all grassland\n", "# drop the state numbers\n", "land = land[land[\"Census Year\"] == 2020]\n", "land = land[land[\"Type of Crop\"] == \"All grassland\"]\n", "land = land[land[\"Electoral Division\"] != \"State\"]" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
STATISTICStatistic LabelTLIST(A1)Census YearC03904V04656Electoral DivisionC02145V02588Type of CropUNITVALUE
20465COALUArea of selected crops202020203576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/0804611114All grasslandHectares964.3
20468COALUArea of selected crops202020203576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/0903511114All grasslandHectares965.4
20471COALUArea of selected crops202020202AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 1000111114All grasslandHectares0
20474COALUArea of selected crops202020202AE19629193513A3E055000000000001St. Laurence Gate, Co.Louth, 1000211114All grasslandHectares0
20477COALUArea of selected crops202020202AE19629191E13A3E055000000000001West Gate, Co.Louth, 1000311114All grasslandHectares0
\n", "
" ], "text/plain": [ " STATISTIC Statistic Label TLIST(A1) Census Year \\\n", "20465 COALU Area of selected crops 2020 2020 \n", "20468 COALU Area of selected crops 2020 2020 \n", "20471 COALU Area of selected crops 2020 2020 \n", "20474 COALU Area of selected crops 2020 2020 \n", "20477 COALU Area of selected crops 2020 2020 \n", "\n", " C03904V04656 \\\n", "20465 3576C59993454152E0530100007F0280 \n", "20468 3576C59992AD4152E0530100007F0280 \n", "20471 2AE1962918C813A3E055000000000001 \n", "20474 2AE19629193513A3E055000000000001 \n", "20477 2AE19629191E13A3E055000000000001 \n", "\n", " Electoral Division C02145V02588 \\\n", "20465 Brisha / Capard, Co.Laois, 08045/08046 11114 \n", "20468 Firry / Newgrove, Co.Longford, 09024/09035 11114 \n", "20471 Fair Gate, Co.Louth, 10001 11114 \n", "20474 St. Laurence Gate, Co.Louth, 10002 11114 \n", "20477 West Gate, Co.Louth, 10003 11114 \n", "\n", " Type of Crop UNIT VALUE \n", "20465 All grassland Hectares 964.3 \n", "20468 All grassland Hectares 965.4 \n", "20471 All grassland Hectares 0 \n", "20474 All grassland Hectares 0 \n", "20477 All grassland Hectares 0 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "land.head()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# rename columns\n", "land.rename(\n", " columns={\n", " \"Electoral Division\": \"electoral_division\",\n", " \"VALUE\": \"total_grass_hectares\",\n", " },\n", " inplace=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "# keep only necessary columns\n", "land = land[[\"C03904V04656\", \"electoral_division\", \"total_grass_hectares\"]]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
C03904V04656electoral_divisiontotal_grass_hectares
204653576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/08046964.3
204683576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/09035965.4
204712AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 100010
204742AE19629193513A3E055000000000001St. Laurence Gate, Co.Louth, 100020
204772AE19629191E13A3E055000000000001West Gate, Co.Louth, 100030
\n", "
" ], "text/plain": [ " C03904V04656 \\\n", "20465 3576C59993454152E0530100007F0280 \n", "20468 3576C59992AD4152E0530100007F0280 \n", "20471 2AE1962918C813A3E055000000000001 \n", "20474 2AE19629193513A3E055000000000001 \n", "20477 2AE19629191E13A3E055000000000001 \n", "\n", " electoral_division total_grass_hectares \n", "20465 Brisha / Capard, Co.Laois, 08045/08046 964.3 \n", "20468 Firry / Newgrove, Co.Longford, 09024/09035 965.4 \n", "20471 Fair Gate, Co.Louth, 10001 0 \n", "20474 St. Laurence Gate, Co.Louth, 10002 0 \n", "20477 West Gate, Co.Louth, 10003 0 " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "land.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Merge datasets" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "data = pd.merge(coa, land, on=[\"C03904V04656\", \"electoral_division\"])" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
C03904V04656electoral_divisiontotal_cattletotal_sheeptotal_grass_hectares
03576C59993454152E0530100007F0280Brisha / Capard, Co.Laois, 08045/080461955420964.3
13576C59992AD4152E0530100007F0280Firry / Newgrove, Co.Longford, 09024/090352164675965.4
22AE1962918C813A3E055000000000001Fair Gate, Co.Louth, 10001000
32AE19629193513A3E055000000000001St. Laurence Gate, Co.Louth, 10002000
42AE19629191E13A3E055000000000001West Gate, Co.Louth, 10003000
\n", "
" ], "text/plain": [ " C03904V04656 \\\n", "0 3576C59993454152E0530100007F0280 \n", "1 3576C59992AD4152E0530100007F0280 \n", "2 2AE1962918C813A3E055000000000001 \n", "3 2AE19629193513A3E055000000000001 \n", "4 2AE19629191E13A3E055000000000001 \n", "\n", " electoral_division total_cattle total_sheep \\\n", "0 Brisha / Capard, Co.Laois, 08045/08046 1955 420 \n", "1 Firry / Newgrove, Co.Longford, 09024/09035 2164 675 \n", "2 Fair Gate, Co.Louth, 10001 0 0 \n", "3 St. Laurence Gate, Co.Louth, 10002 0 0 \n", "4 West Gate, Co.Louth, 10003 0 0 \n", "\n", " total_grass_hectares \n", "0 964.3 \n", "1 965.4 \n", "2 0 \n", "3 0 \n", "4 0 " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.head()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Int64Index([ 6, 10, 16, 23, 26, 30, 36, 42, 46, 47,\n", " ...\n", " 3370, 3376, 3378, 3383, 3384, 3386, 3393, 3396, 3400, 3403],\n", " dtype='int64', length=935)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# check for missing data\n", "data.index[data.isnull().any(axis=1)]" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "# fill with zero\n", "data.fillna(0, inplace=True)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Int64Index([], dtype='int64')" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.index[data.isnull().any(axis=1)]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "# save as a CSV file\n", "data.to_csv(os.path.join(SUB_DIR, \"COA_2020.csv\"), index=False)" ] } ], "metadata": { "kernelspec": { "display_name": "ClimAg", "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.10.6" }, "vscode": { "interpreter": { "hash": "c4e659d1bedfc73d1fd31d7c0e2c79d7cc7aac22204994016c65a9e44686eb91" } } }, "nbformat": 4, "nbformat_minor": 2 }