{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This file is part of the Minnesota Population Center's NHGISXWALK.\n", "# For copyright and licensing information, see the NOTICE and LICENSE files\n", "# in this project's top-level directory, and also on-line at:\n", "# https://github.com/ipums/nhgisxwalk" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Generate national and state-level crosswalks\n", "## 2000 block group parts to 2010 county\n", "\n", "### NHGIS [block crosswalks](https://www.nhgis.org/user-resources/geographic-crosswalks)\n", "\n", "**James D. Gaboardi, 06/2020**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:19.285459Z", "start_time": "2020-10-01T21:53:19.140633Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2020-10-01T17:53:19-04:00\n", "\n", "CPython 3.8.5\n", "IPython 7.18.1\n", "\n", "compiler : Clang 10.0.1 \n", "system : Darwin\n", "release : 19.6.0\n", "machine : x86_64\n", "processor : i386\n", "CPU cores : 8\n", "interpreter: 64bit\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:19.555408Z", "start_time": "2020-10-01T21:53:19.287875Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "watermark 2.0.2\n", "pandas 1.1.1\n", "numpy 1.19.1\n", "nhgisxwalk 0.0.9post1\n", "\n" ] } ], "source": [ "import nhgisxwalk\n", "import inspect\n", "import numpy\n", "import pandas\n", "\n", "%load_ext autoreload\n", "%autoreload 2\n", "%watermark -w\n", "%watermark -iv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Source and target years for the crosswalk" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:19.574264Z", "start_time": "2020-10-01T21:53:19.558483Z" } }, "outputs": [], "source": [ "source_year, target_year = \"2000\", \"2010\"\n", "gj_src, gj_trg = \"GJOIN%s\"%source_year, \"GJOIN%s\"%target_year" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:19.592374Z", "start_time": "2020-10-01T21:53:19.576945Z" } }, "outputs": [], "source": [ "# Set these to a local directory\n", "data_in = \"path/to/data/\"\n", "data_tab = \"path/to/data/\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:19.608098Z", "start_time": "2020-10-01T21:53:19.594045Z" } }, "outputs": [], "source": [ "block_file = \"%s_block\" % source_year" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Source-target building base" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-10-01T21:53:33.317361Z", "start_time": "2020-10-01T21:53:19.609436Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | GJOIN2000 | \n", "GJOIN2010 | \n", "WEIGHT | \n", "PAREA | \n", "
|---|---|---|---|---|
| 0 | \n", "G01000100201001000 | \n", "G01000100201002000 | \n", "0.035897 | \n", "0.008988 | \n", "
| 1 | \n", "G01000100201001000 | \n", "G01000100201002001 | \n", "0.253330 | \n", "0.263725 | \n", "
| 2 | \n", "G01000100201001000 | \n", "G01000100201002002 | \n", "0.000000 | \n", "0.000385 | \n", "
| 3 | \n", "G01000100201001000 | \n", "G01000100201002003 | \n", "0.076297 | \n", "0.055430 | \n", "
| 4 | \n", "G01000100201001000 | \n", "G01000100201002004 | \n", "0.032441 | \n", "0.007543 | \n", "