From f4d785490a81531c1892261405cbbf69bbb7d567 Mon Sep 17 00:00:00 2001
From: wiltand1 <59701260+wiltand1@users.noreply.github.com>
Date: Fri, 18 Feb 2022 16:00:50 -0500
Subject: [PATCH] Add files via upload

Adding notebook to census branch.
---
 censusdata tutorail.ipynb | 289 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 289 insertions(+)
 create mode 100644 censusdata tutorail.ipynb

diff --git a/censusdata tutorail.ipynb b/censusdata tutorail.ipynb
new file mode 100644
index 0000000..65a163c
--- /dev/null
+++ b/censusdata tutorail.ipynb	
@@ -0,0 +1,289 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "78ccb82d",
+   "metadata": {},
+   "source": [
+    "# Censusdata tutorial\n",
+    "\n",
+    "Useful link:\n",
+    "\n",
+    "https://jtleider.github.io/censusdata/example1.html\n",
+    "\n",
+    "https://jtleider.github.io/censusdata/api.html\n",
+    "\n",
+    "https://jtleider.github.io/censusdata/example3.html"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "dc5fcca9",
+   "metadata": {},
+   "source": [
+    "### Install censusdata library"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "54211a3c",
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Collecting censusdata\n",
+      "  Downloading CensusData-1.15.tar.gz (26.6 MB)\n",
+      "\u001b[K     |████████████████████████████████| 26.6 MB 5.5 MB/s eta 0:00:01\n",
+      "\u001b[?25hRequirement already satisfied: pandas in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from censusdata) (1.3.4)\n",
+      "Requirement already satisfied: requests in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from censusdata) (2.27.1)\n",
+      "Requirement already satisfied: python-dateutil>=2.7.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (2.8.2)\n",
+      "Requirement already satisfied: pytz>=2017.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (2021.3)\n",
+      "Requirement already satisfied: numpy>=1.17.3 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from pandas->censusdata) (1.20.3)\n",
+      "Requirement already satisfied: six>=1.5 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas->censusdata) (1.16.0)\n",
+      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (1.26.7)\n",
+      "Requirement already satisfied: idna<4,>=2.5 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (3.2)\n",
+      "Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (2.0.4)\n",
+      "Requirement already satisfied: certifi>=2017.4.17 in /Users/liruohong/opt/anaconda3/lib/python3.9/site-packages (from requests->censusdata) (2021.10.8)\n",
+      "Building wheels for collected packages: censusdata\n",
+      "  Building wheel for censusdata (setup.py) ... \u001b[?25ldone\n",
+      "\u001b[?25h  Created wheel for censusdata: filename=CensusData-1.15-py3-none-any.whl size=28205534 sha256=67f5d3391f90bc0e7dba31614e537f4acd16155c871442aeb1cd9a322a4f3f14\n",
+      "  Stored in directory: /Users/liruohong/Library/Caches/pip/wheels/f7/28/2d/3308dceb3ca282b1479585690170f0a00821d9b36cbf835159\n",
+      "Successfully built censusdata\n",
+      "Installing collected packages: censusdata\n",
+      "Successfully installed censusdata-1.15\n",
+      "Note: you may need to restart the kernel to use updated packages.\n"
+     ]
+    }
+   ],
+   "source": [
+    "pip install censusdata"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "e7581483",
+   "metadata": {},
+   "source": [
+    "### Import libararys\n",
+    "Import censusdata libararys\n",
+    "\n",
+    "Import pandas libarary for data processing"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "dbda6a76",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import pandas as pd\n",
+    "import censusdata"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "569bec68",
+   "metadata": {},
+   "source": [
+    "### Method of censusdata library\n",
+    "censusdata.search(src, year,field, criterion,tabletype): search for given text patterns\n",
+    "\n",
+    "censusdata.censustable():identified table of interest\n",
+    "\n",
+    "censusdata.printtable():show all variables included in the identified table of interest\n",
+    "\n",
+    "censusdata.geographies():\n",
+    "\n",
+    "censusdata.download():download the selected data"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "5b7a5a3e",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[('B23024_023E',\n",
+       "  'POVERTY STATUS IN THE PAST 12 MONTHS BY DISABILITY STATUS BY EMPLOYMENT STATUS FOR THE POPULATION 20 TO 64 YEARS',\n",
+       "  'Estimate!!Total!!Income in the past 12 months at or above poverty level!!With a disability!!In labor force!!Civilian!!Unemployed'),\n",
+       " ('B23024_030E',\n",
+       "  'POVERTY STATUS IN THE PAST 12 MONTHS BY DISABILITY STATUS BY EMPLOYMENT STATUS FOR THE POPULATION 20 TO 64 YEARS',\n",
+       "  'Estimate!!Total!!Income in the past 12 months at or above poverty level!!No disability!!In labor force!!Civilian!!Unemployed'),\n",
+       " ('B23025_005E',\n",
+       "  'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER',\n",
+       "  'Estimate!!Total!!In labor force!!Civilian labor force!!Unemployed'),\n",
+       " ('B27011_014E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed'),\n",
+       " ('B27011_015E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years'),\n",
+       " ('B27011_016E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage'),\n",
+       " ('B27011_017E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage!!With private health insurance'),\n",
+       " ('B27011_018E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!With health insurance coverage!!With public coverage'),\n",
+       " ('B27011_019E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!18 to 64 years!!No health insurance coverage'),\n",
+       " ('B27011_020E',\n",
+       "  'HEALTH INSURANCE COVERAGE STATUS AND TYPE BY EMPLOYMENT STATUS BY AGE',\n",
+       "  'Estimate!!Total!!In labor force!!Unemployed!!65 years and over')]"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "censusdata.search('acs5', 2015, 'label', 'unemploy')[80:90]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "40cbfb96",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Variable     | Table                          | Label                                                    | Type \n",
+      "-------------------------------------------------------------------------------------------------------------------\n",
+      "B23025_001E  | EMPLOYMENT STATUS FOR THE POPU | !! Estimate Total                                        | int  \n",
+      "B23025_002E  | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total In labor force                      | int  \n",
+      "B23025_003E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Civilian labor fo | int  \n",
+      "B23025_004E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int  \n",
+      "B23025_005E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int  \n",
+      "B23025_006E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Armed Forces      | int  \n",
+      "B23025_007E  | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total Not in labor force                  | int  \n",
+      "-------------------------------------------------------------------------------------------------------------------\n"
+     ]
+    }
+   ],
+   "source": [
+    "censusdata.printtable(censusdata.censustable('acs5', 2015, 'B23025'))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "2bf2bc44",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Variable     | Table                          | Label                                                    | Type \n",
+      "-------------------------------------------------------------------------------------------------------------------\n",
+      "B23025_001E  | EMPLOYMENT STATUS FOR THE POPU | !! Estimate Total                                        | int  \n",
+      "B23025_002E  | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total In labor force                      | int  \n",
+      "B23025_003E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Civilian labor fo | int  \n",
+      "B23025_004E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int  \n",
+      "B23025_005E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! !! Estimate Total In labor force Civilian labor | int  \n",
+      "B23025_006E  | EMPLOYMENT STATUS FOR THE POPU | !! !! !! Estimate Total In labor force Armed Forces      | int  \n",
+      "B23025_007E  | EMPLOYMENT STATUS FOR THE POPU | !! !! Estimate Total Not in labor force                  | int  \n",
+      "-------------------------------------------------------------------------------------------------------------------\n"
+     ]
+    }
+   ],
+   "source": [
+    "censusdata.printtable(censusdata.censustable('acs5', 2015, 'B23025'))"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "1a3e0003",
+   "metadata": {},
+   "source": [
+    "### Class for representing Census geographies: censusdata.censusgeo(geo,name)\n",
+    "\n",
+    "censusdata.censusgeo.hierarchy():Geography hierarchy for the geographic level of this object\n",
+    "\n",
+    "censusdata.censusgeo.params():Geographic parameters of this object.\n",
+    "\n",
+    "censusdata.censusgeo.request():Generate geographic parameters for Census API request.\n",
+    "\n",
+    "censusdata.censusgeo.sumlevel():Summary level code for the geographic level of this object."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "4572b9e7",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Summary level: 050, state:17> county:031\n",
+      "(('state', '17'), ('county', '031'))\n",
+      "{'for': 'county:031', 'in': 'state:17'}\n",
+      "050\n"
+     ]
+    }
+   ],
+   "source": [
+    "geo = censusdata.censusgeo([('state', '17'), ('county', '031')])\n",
+    "print(geo)\n",
+    "print(geo.params())\n",
+    "print(geo.request())\n",
+    "print(geo.sumlevel())"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "e8d800b3",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "ec541cba",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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.9.7"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
-- 
GitLab