{ "cells": [ { "cell_type": "markdown", "id": "af9d0bd0", "metadata": {}, "source": [ "# Compiling, homogenizing, and quality-controlling King County bike-related citation records\n", "\n", "##### Ethan C. Campbell, for Central Seattle Greenways / Helmet Law Working Group\n", "\n", "For questions, contact me at ethanchenbell@gmail.com.\n", "\n", "For analysis of the data compiled below, refer to the companion notebook on my GitHub: [***csg_analyze_king_county_bike_citations.ipynb***](https://github.com/ethan-campbell/Miscellaneous/blob/master/csg_analyze_king_county_bike_citations.ipynb)." ] }, { "cell_type": "markdown", "id": "c3fdf788", "metadata": {}, "source": [ "#### Import packages and set file system" ] }, { "cell_type": "code", "execution_count": 333, "id": "76d408bd", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "from numpy import *\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib.dates as mdates\n", "import matplotlib as mpl\n", "# mpl.rcParams['figure.dpi'] = 300 # turn on for higher-quality figure export\n", "from datetime import datetime, timedelta\n", "import platform\n", "import warnings\n", "import sys\n", "\n", "from IPython.core.display import display, HTML\n", "# display(HTML(\"\"))\n", "\n", "# choose root directory for data files\n", "if platform.system() == 'Darwin':\n", " data_dir = '/Users/Ethan/Documents/Finances and records/2020-06-30 - Helmet Law Working Group/Data/'\n", "elif platform.system() == 'Linux':\n", " data_dir = '/dat1/ethancc/CSG/'\n", " \n", "# filepaths\n", "aoc_dir = data_dir + '2021-06-22 - WA State Administrative Office of the Courts data/'" ] }, { "cell_type": "markdown", "id": "b338682a", "metadata": {}, "source": [ "#### Load and merge bike citation records from WA State Administrative Office of the Courts (AOC)" ] }, { "cell_type": "code", "execution_count": 334, "id": "55a9ae68", "metadata": {}, "outputs": [], "source": [ "# load bike infraction data from WA State Administrative Office of the Courts\n", "# note: \"KCDC\" = King County District Court\n", "# \"KCMC\" / \"MCs\" = municipal courts in King County\n", "kcdc_citations = pd.read_excel(aoc_dir + '210419-000051_KCDC_Bicycle_Viols - updated.xlsx',header=2,skipfooter=1)\n", "kcmc_citations = pd.read_excel(aoc_dir + '210419-000051_KCMC_Bicycle_Viols - updated.xlsx',header=3,sheet_name='Bicycle Charges')\n", "kcmc_lea_data = pd.read_excel(aoc_dir + '210419-000051_KCMC_Bicycle_Viols - updated.xlsx',header=2,sheet_name='LEA')\n", "kcmc_lfo_data = pd.read_excel(aoc_dir + '210419-000051_KCMC_Bicycle_Viols - updated.xlsx',header=2,sheet_name='LFOs')\n", "\n", "# merge in data on officers, badge numbers, and accounts receivables (AR) charges (all provided for municipal courts only)\n", "kcmc_lea_data = kcmc_lea_data.drop(columns=['Court Name','Case Token','Case LEA Name'])\n", "kcmc_citations = kcmc_citations.merge(kcmc_lea_data,how='left',on='Case Number')\n", "kcmc_lfo_data = kcmc_lfo_data.drop(columns=['Court Name','Case Token'])\n", "kcmc_citations = kcmc_citations.merge(kcmc_lfo_data,how='left',on='Case Number')\n", "\n", "# standardize column names\n", "kcdc_citations = kcdc_citations.rename(columns={'Case Key':'Case Key (KCDC) or Token (MCs)',\n", " 'Case Type Code & Desc':'Case Type',\n", " 'Case LEA':'Law Enforcement Agency',\n", " 'Charge Violation Date':'Violation Date',\n", " 'Charge Law Number':'Law Code',\n", " 'Charge Law':'Law Description',\n", " 'Charge Result':'Disposition',\n", " 'Charge Result Date':'Disposition Date',\n", " 'Case Participant Actor Name':'Defendant Name',\n", " 'Actor Person Gender':'Defendant Gender',\n", " 'Actor Person Race':'Defendant Race',\n", " 'Actor Person Ethnicity':'Defendant Ethnicity'})\n", "kcmc_citations = kcmc_citations.rename(columns={'Case Token':'Case Key (KCDC) or Token (MCs)',\n", " 'Case LEA Name':'Law Enforcement Agency',\n", " 'Case Citation Charge Date':'Violation Date',\n", " 'Charge Law Number':'Law Code',\n", " 'Charge':'Law Description',\n", " 'Charge Disposition':'Disposition',\n", " 'Charge Disposition Date':'Disposition Date',\n", " 'Person Name':'Defendant Name',\n", " 'Person Gender':'Defendant Gender',\n", " 'Person Race':'Defendant Race',\n", " 'Person Ethnicity':'Defendant Ethnicity',\n", " 'Official Name':'Officer Name',\n", " 'Official Officer Badge Number':'Officer Badge Number'})\n", "\n", "# redact identifying defendant data and unneeded columns\n", "# NOTE: keep only Federal Way Municipal Court defendant names to allow checking for duplicate citations with separate FWMC data\n", "kcdc_citations = kcdc_citations.drop(columns=['#Age at Viol Dt','Case Participant Type Code'])\n", "kcmc_citations = kcmc_citations.drop(columns=['#Age at Viol Dt','Specific Participant Type Code'])\n", "kcdc_citations['Defendant Name'] = NaN\n", "kcmc_citations.loc[kcmc_citations['Court Name'] != 'FEDERAL WAY MUNICIPAL COURT','Defendant Name'] = NaN\n", "\n", "# merge KCDC and MC data\n", "kc_citations = pd.concat([kcmc_citations,kcdc_citations],ignore_index=True)\n", "\n", "# flag all as originating from query for helmet and non-helmet bike violations\n", "kc_citations['Originating Query'] = 'All bike violations (requested KCHC 9.10.010 and 9.15.010, RCW sections, WAC sections, and local code chapters)'" ] }, { "cell_type": "markdown", "id": "2ad4a51f", "metadata": {}, "source": [ "#### Remove records that are not bike-related" ] }, { "cell_type": "code", "execution_count": 335, "id": "ce3a197c", "metadata": {}, "outputs": [], "source": [ "# remove one citation under King County Code 14A.40.010d (requiring motorized foot scooter users to wear a helmet)\n", "kc_citations = kc_citations[kc_citations['Law Code'] != 'kcc14a.40.010.d']\n", "\n", "# remove three concurrent citations for single person by North Bend Police Department, two of which are \"bicycle\" citations\n", "# but the third of which is under NBMC 10.20.030 (requiring motorized foot scooter users to wear a helmet)\n", "kc_citations = kc_citations[kc_citations['Case Number'] != '4Z0454185']\n", "\n", "# remove one citation under Kent Municipal Code 9.44.050 (requiring motorized foot scooter users to wear a helmet)\n", "kc_citations = kc_citations[kc_citations['Law Code'] != '9.44.050']" ] }, { "cell_type": "markdown", "id": "acfa25dc", "metadata": {}, "source": [ "#### Standardize and homogenize data" ] }, { "cell_type": "code", "execution_count": 336, "id": "c6b54470", "metadata": {}, "outputs": [], "source": [ "kc_citations['Court Name'] = kc_citations['Court Name'].str.title()\n", "kc_citations.replace({'Court Name':{'King District Court - Kcdc':'King County District Court',\n", " 'Kcdc Auburn Courthouse':'King County District Court',\n", " 'Seatac Municipal Court':'SeaTac Municipal Court'}},inplace=True)\n", "kc_citations.replace({'Case Type':{'IN - Infraction':'Infraction',\n", " 'CR - Criminal':'Criminal',\n", " \"Defendant's race\":'Infraction',\n", " 'Limited to the defendant':'Infraction',\n", " 'Calculated by days between defendant birth date and charge violation date':'Infraction',\n", " 'defendant gender':'Infraction'}},inplace=True)\n", "kc_citations['Law Enforcement Agency'] = kc_citations['Law Enforcement Agency'].str.title()\n", "kc_citations.replace({'Law Enforcement Agency':{'Maple Valley Police Department':\"King County Sheriff's Office / Maple Valley Police Department\",\n", " 'Burien Police Department':\"King County Sheriff's Office / Burien Police Department\",\n", " 'Covington Police Department':\"King County Sheriff's Office / Covington Police Department\",\n", " 'Kenmore City Of':\"King County Sheriff's Office / Kenmore Police Department\",\n", " 'Woodinville Police Department':\"King County Sheriff's Office / Woodinville Police Department\",\n", " 'Sammamish Police Department':\"King County Sheriff's Office / Sammamish Police Department\",\n", " 'King Co Police Department':\"King County Sheriff's Office\",\n", " 'Lake Forest Park Police Dept':'Lake Forest Park Police Department',\n", " 'Port Of Seattle Police Department':'Port of Seattle Police Department',\n", " 'Seatac Police Department':\"King County Sheriff's Office / SeaTac Police Department\",\n", " 'Shoreline City Of':\"King County Sheriff's Office / Shoreline Police Department\",\n", " 'University Of Washington Police':'University Of Washington Police Department',\n", " 'Wa St Patrol':'Washington State Patrol'}},inplace=True)\n", "kc_citations.loc[logical_and(kc_citations['Law Enforcement Agency'] == 'North Bend Police Department',\n", " kc_citations['Violation Date'] <= datetime(2014,3,8)),\n", " 'Law Enforcement Agency'] = \"King County Sheriff's Office / North Bend Police Department\"\n", "kc_citations.loc[logical_and(kc_citations['Law Enforcement Agency'] == 'North Bend Police Department',\n", " kc_citations['Violation Date'] > datetime(2014,3,8)),\n", " 'Law Enforcement Agency'] = \"Snoqualmie/North Bend Police Department\"\n", "kc_citations.loc[logical_and(kc_citations['Law Enforcement Agency'] == 'Snoqualmie Police Department',\n", " kc_citations['Violation Date'] > datetime(2014,3,8)),\n", " 'Law Enforcement Agency'] = \"Snoqualmie/North Bend Police Department\"\n", "\n", "kc_citations['Law Description'] = kc_citations['Law Description'].str.title()\n", "kc_citations.replace({'Law Description':{'Bicycle Helmet Regulations':'Bicycle Helmet Required',\n", " 'Bicycle Helmet Violation':'Bicycle Helmet Required',\n", " 'Bicycle Helmets':'Bicycle Helmet Required',\n", " 'Fail To Wear Bicycle Helmet':'Bicycle Helmet Required',\n", " 'Helmet Required':'Bicycle Helmet Required',\n", " 'Helmet Required Riding Bicycle':'Bicycle Helmet Required',\n", " 'Helmet Required When Riding Bicyle':'Bicycle Helmet Required',\n", " 'No Bicycle Helmet':'Bicycle Helmet Required',\n", " 'No Bicyle Helmet':'Bicycle Helmet Required',\n", " 'Require Bicycle Helmet Guardian Of':'Bicycle Helmet Required (Guardian of Minor)',\n", " 'Requirement Re Bicycle Helmet':'Bicycle Helmet Required',\n", " 'Riding Bicycle W/O Helmet':'Bicycle Helmet Required',\n", " 'Riding Bicycle W/Out Helmet':'Bicycle Helmet Required',\n", " 'Riding Bicycle Without Helmet':'Bicycle Helmet Required',\n", " 'Bicycle Fail To Yield':'Bicycle Failure to Yield',\n", " 'Bicycle Leaving Curb X-Walk Spd Zn':'Bicycle Leaving Curb or Crosswalk in Speed Zone',\n", " 'No Bicycle Lights As Required':'Bicycle Lights Required',\n", " 'Bicycle Riding On Sidewalk':'Bicycle Riding on Sidewalk',\n", " 'Bicycle Riding On Sidewalks':'Bicycle Riding on Sidewalk',\n", " 'Defective Equipment-Bicycle':'Bicycle Defective Equipment',\n", " 'Bicycle-Fail To Stop At Stop Sign':'Bicycle Failure to Stop at Stop Sign',\n", " 'Bicycle-Negligence':'Bicycle Negligence',\n", " 'Bicycles Obedience To Traffic Dev':'Bicycle Obedience to Traffic Control Devices',\n", " 'Bicycles Ride On Right Side':'Riding Bicycle on Right Side',\n", " 'Bike On Sidewalk In Business Dist':'Bicycle on Sidewalk in Business District',\n", " 'Carrying Articles On Bicycle':'Carrying Articles on Bicycle',\n", " 'Fld To Give Hand Signals/Bike':'Bicycle Failure to Give Hand Signals',\n", " 'Improper Operation Of Bicycle':'Improper Operation of Bicycle',\n", " 'No Bicycles On Skate Park':'No Bicycles on Skate Park',\n", " 'Ride Bicycle On Transit Property':'Riding Bicycle on Transit Property',\n", " 'Riding Bicycle On Sidewalk/Path':'Riding Bicycle on Sidewalk or Path',\n", " 'Riding Bicycles On Right Side':'Riding Bicycle on Right Side',\n", " 'Speeding On Bicycle Trail':'Speeding on Bicycle Trail',\n", " 'Unlawful Riding On Bicycle':'Unlawful Riding on Bicycle',\n", " 'Violating Laws While Riding Bike':'Violating Laws While Riding Bicycle'}},inplace=True)\n", "kc_citations.loc[logical_and(kc_citations['Law Code'] == '46.61.780',\n", " kc_citations['Law Description'] == 'Bicycle Violation'),\n", " 'Law Description'] = 'Bicycle Defective Equipment'\n", "kc_citations.replace({'Disposition':{'Dismissed W/Prejudice':'Dismissed with Prejudice',\n", " 'Dismissed W/O Prejudice':'Dismissed without Prejudice',\n", " 'Dismissed After Deferral':'Dismissed after Deferral',\n", " 'Committed After Deferral':'Committed after Deferral'}},inplace=True)\n", "kc_citations.replace({'Defendant Race':{'White (Caucasian)':'White',\n", " 'Black (African American)':'Black',\n", " 'Asian':'Asian or Pacific Islander',\n", " 'Unknown':'Unknown/Other',\n", " 'Multiracial':'Unknown/Other'}},inplace=True)\n", "kc_citations.replace({'Defendant Ethnicity':{'Hispanic':'Hispanic/Latino',\n", " 'Hispanic or Latino':'Hispanic/Latino',\n", " 'Non-Hispanic':'Not Hispanic/Latino',\n", " 'Not Hispanic or Latino':'Not Hispanic/Latino'}},inplace=True)\n", "kc_citations['Officer Name'] = kc_citations['Officer Name'].str.title()\n", "combined_officer_strings = [name for name in kc_citations['Officer Name'].value_counts().index if ' ' in name]\n", "fixed_officer_strings = [name.split(' ')[0] for name in kc_citations['Officer Name'].value_counts().index if ' ' in name]\n", "for ofc_idx, ofc_name in enumerate(combined_officer_strings):\n", " kc_citations.replace({'Officer Name':{ofc_name:fixed_officer_strings[ofc_idx]}},inplace=True)\n", "kc_citations.replace({'Law Code':{'D.10.12.010(1)':'Des Moines Municipal Code 10.12.010 or 10.12.010(1)',\n", " 'ECM1804':'[Enumclaw - no match found] \"ECM 1804\"',\n", " 'ECM1807':'[Enumclaw - no match found] \"ECM 1807\"',\n", " 'MVO.8.15.030A':'Maple Valley Municipal Code 8.15.030 or 8.15.030A',\n", " 'M8.15.030':'Maple Valley Municipal Code 8.15.030 or 8.15.030A',\n", " 'FWRC8.25.060':'Federal Way Revised Code 8.25.060',\n", " 'FWC15.196':'Federal Way Revised Code 8.25.060',\n", " 'IQM10.44.025':'Issaquah Municipal Code 10.44.025',\n", " 'SNL10.30.050':'Snoqualmie Municipal Code 10.30.050',\n", " 'K9.41.030':'Kent City Code 9.41.030',\n", " '9.41.030':'Kent City Code 9.41.030',\n", " 'LFM9.18.020':'Lake Forest Park Municipal Code 9.18.020',\n", " '10.54.080':'Pacific Municipal Code 10.54.080',\n", " 'P.10.54.080':'Pacific Municipal Code 10.54.080',\n", " 'R6-26(3)(A)':'Renton Municipal Code 6-26-3(A) or 6-26-7',\n", " 'R6-26-7':'Renton Municipal Code 6-26-3(A) or 6-26-7',\n", " '10.56.185':'Auburn City Code 10.56.185',\n", " 'amc 10.56.185':'Auburn City Code 10.56.185',\n", " 'amc10.56.185':'Auburn City Code 10.56.185',\n", " 'ke9.05.450':'Kenmore Municipal Code 9.05.450 (partially adopts KCHC Title 9 by reference)',\n", " 'be11.60.090':'Bellevue City Code 11.60.090',\n", " 'bu8.37.050':'Burien Municipal Code 8.37.050 or 8.37.050.1',\n", " 'bu8.37.050.1':'Burien Municipal Code 8.37.050 or 8.37.050.1',\n", " 'KCHC9.10.010A':'King County Health Code 9.10.010A or 9.15.010',\n", " '9.10.010.a':'King County Health Code 9.10.010A or 9.15.010',\n", " '9.15.010':'King County Health Code 9.10.010A or 9.15.010',\n", " '9.10.010.b':'King County Health Code 9.10.010B'}},inplace=True)\n", "kc_citations.replace({'Law Code':{'46.61.780':'RCW 46.61.780',\n", " '46.61.755':'RCW 46.61.755',\n", " '46.61.770':'RCW 46.61.770',\n", " '46.61.758':'RCW 46.61.758',\n", " '46.61.775':'RCW 46.61.775',\n", " '46.61.760':'RCW 46.61.760',\n", " '46.61.235.2B':'RCW 46.61.235.2B',\n", " '46.61.235.2b':'RCW 46.61.235.2B',\n", " '46.61.235.5-2b':'RCW 46.61.235.2B/5',\n", " '308.330.545':'WAC 308-330-545',\n", " '308.330.555':'WAC 308-330-555',\n", " '308-330-555':'WAC 308-330-555',\n", " 'KCC7.12.295.A':'King County Code 7.12.295 or 7.12.295.A',\n", " '28.96.010.a4':'King County Code 28.96.010.A4',\n", " 'amc 10.56.110':'Auburn City Code 10.56.110',\n", " 'amc10.56.110':'Auburn City Code 10.56.110',\n", " '10.56.110':'Auburn City Code 10.56.110',\n", " '10.56.120':'Auburn City Code 10.56.120',\n", " '10.56.140':'Auburn City Code 10.56.140',\n", " 'amc 10.56.140':'Auburn City Code 10.56.140',\n", " 'LFMORD798.2D':'Lake Forest Park Ordinance 798.2D',\n", " 'LFM798.2B':'Lake Forest Park Ordinance 798.2B',\n", " 'FWRC8.25.020.1':'Federal Way Revised Code 8.52.010.1',\n", " 'smc11.44.120':'Seattle Municipal Code 11.44.120',\n", " 'BDM8.28.040':'Black Diamond Municipal Code 8.28.040'}},inplace=True)" ] }, { "cell_type": "markdown", "id": "cd6160cd", "metadata": {}, "source": [ "#### Load and merge Des Moines Municipal Court records" ] }, { "cell_type": "code", "execution_count": 337, "id": "fd4f1450", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Court Name | \n", "Case Number | \n", "Violation Date | \n", "Law Code | \n", "Law Description | \n", "Officer Name | \n", "Officer Badge Number | \n", "Defendant Race | \n", "Defendant Gender | \n", "
---|